# Path: modules/foncia/constants.py
# AVAILABLE_TYPES = {
#     POSTS_TYPES.RENT: ['appartement', 'maison', 'parking', 'chambre',
#                        'local-commercial'],
#     POSTS_TYPES.SALE: ['appartement', 'maison', 'parking', 'local-commercial',
#                        'terrain', 'immeuble', 'programme-neuf'],
#     POSTS_TYPES.FURNISHED_RENT: ['appartement-meuble']
# }
# 
# QUERY_TYPES = {
#     POSTS_TYPES.RENT: 'location',
#     POSTS_TYPES.SALE: 'achat',
#     POSTS_TYPES.FURNISHED_RENT: 'location'
# }
# 
# QUERY_HOUSE_TYPES = {
#     HOUSE_TYPES.APART: ['appartement', 'appartement-meuble'],
#     HOUSE_TYPES.HOUSE: ['maison'],
#     HOUSE_TYPES.PARKING: ['parking'],
#     HOUSE_TYPES.LAND: ['terrain'],
#     HOUSE_TYPES.OTHER: ['chambre', 'programme-neuf',
#                         'local-commercial', 'immeuble']
# }


import datetime
from woob.browser.pages import JsonPage, HTMLPage, pagination
from woob.browser.filters.standard import (
    CleanDecimal, CleanText, Currency, Date, Env, Format, Regexp, RegexpError
)
from woob.browser.filters.html import AbsoluteLink, Attr, Link, XPathNotFound
from woob.browser.elements import ItemElement, ListElement, method
from woob.capabilities.base import NotAvailable, NotLoaded
from woob.capabilities.housing import (
    City, Housing, HousingPhoto,
    UTILITIES, ENERGY_CLASS, POSTS_TYPES, ADVERT_TYPES
)
from woob.tools.capabilities.housing.housing import PricePerMeterFilter
from .constants import AVAILABLE_TYPES, QUERY_TYPES, QUERY_HOUSE_TYPES

    def find_housing(self, query_type, housing):
        form = self.get_form('//form[@name="searchForm"]')
        form['searchForm[type]'] = query_type
        form['searchForm[reference]'] = housing
        form.submit()


class SearchResultsPage(HTMLPage):
    @pagination
    @method
    class iter_housings(ListElement):
        item_xpath = '//article[has-class("TeaserOffer")]'

        next_page = Link('//div[has-class("Pagination--more")]/a[contains(text(), "Suivant")]')

        class item(ItemElement):
            klass = Housing

            obj_id = Format(
                '%s:%s',
                Env('type'),
                Attr('.//span[boolean(@data-reference)]', 'data-reference')
            )
            obj_url = AbsoluteLink('.//h3[has-class("TeaserOffer-title")]/a')
            obj_type = Env('query_type')
            obj_advert_type = ADVERT_TYPES.PROFESSIONAL

            def obj_house_type(self):
                url = self.obj_url(self)

# Path: modules/foncia/constants.py
# AVAILABLE_TYPES = {
#     POSTS_TYPES.RENT: ['appartement', 'maison', 'parking', 'chambre',
#                        'local-commercial'],
#     POSTS_TYPES.SALE: ['appartement', 'maison', 'parking', 'local-commercial',
#                        'terrain', 'immeuble', 'programme-neuf'],
#     POSTS_TYPES.FURNISHED_RENT: ['appartement-meuble']
# }
# 
# QUERY_TYPES = {
#     POSTS_TYPES.RENT: 'location',
#     POSTS_TYPES.SALE: 'achat',
#     POSTS_TYPES.FURNISHED_RENT: 'location'
# }
# 
# QUERY_HOUSE_TYPES = {
#     HOUSE_TYPES.APART: ['appartement', 'appartement-meuble'],
#     HOUSE_TYPES.HOUSE: ['maison'],
#     HOUSE_TYPES.PARKING: ['parking'],
#     HOUSE_TYPES.LAND: ['terrain'],
#     HOUSE_TYPES.OTHER: ['chambre', 'programme-neuf',
#                         'local-commercial', 'immeuble']
# }


# Path: modules/foncia/pages.py
import datetime
from woob.browser.pages import JsonPage, HTMLPage, pagination
from woob.browser.filters.standard import (
    CleanDecimal, CleanText, Currency, Date, Env, Format, Regexp, RegexpError
)
from woob.browser.filters.html import AbsoluteLink, Attr, Link, XPathNotFound
from woob.browser.elements import ItemElement, ListElement, method
from woob.capabilities.base import NotAvailable, NotLoaded
from woob.capabilities.housing import (
    City, Housing, HousingPhoto,
    UTILITIES, ENERGY_CLASS, POSTS_TYPES, ADVERT_TYPES
)
from woob.tools.capabilities.housing.housing import PricePerMeterFilter
from .constants import AVAILABLE_TYPES, QUERY_TYPES, QUERY_HOUSE_TYPES


    def find_housing(self, query_type, housing):
        form = self.get_form('//form[@name="searchForm"]')
        form['searchForm[type]'] = query_type
        form['searchForm[reference]'] = housing
        form.submit()


class SearchResultsPage(HTMLPage):
    @pagination
    @method
    class iter_housings(ListElement):
        item_xpath = '//article[has-class("TeaserOffer")]'

        next_page = Link('//div[has-class("Pagination--more")]/a[contains(text(), "Suivant")]')

        class item(ItemElement):
            klass = Housing

            obj_id = Format(
                '%s:%s',
                Env('type'),
                Attr('.//span[boolean(@data-reference)]', 'data-reference')
            )
            obj_url = AbsoluteLink('.//h3[has-class("TeaserOffer-title")]/a')
            obj_type = Env('query_type')
            obj_advert_type = ADVERT_TYPES.PROFESSIONAL

            def obj_house_type(self):
                url = self.obj_url(self)

                for house_type, types in QUERY_HOUSE_TYPES.items():