<?xml version="1.0" encoding="UTF-8"?>
<!--
  XSD schéma formátu "bydo XML" (docs/api/bydo-xml.md) - štrukturálna kontrola súboru (elementy, typy,
  povinnosť), nie plná obchodná validácia (tá je v importe, napr. "city alebo city_part", povolené
  hodnoty výčtov sú zdokumentované v markdowne, nie tu - zdroj posiela aj hodnoty, ktoré mapovanie
  ešte nepozná, a to nie je chyba importu).
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xs:element name="export">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="listing" type="listingType" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="portal" type="xs:string" use="optional"/>
            <xs:attribute name="generated" type="xs:string" use="optional"/>
            <xs:attribute name="count" type="xs:integer" use="optional"/>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="listingType">
        <xs:all>
            <xs:element name="id" type="xs:string"/>
            <xs:element name="ref_code" type="xs:string" minOccurs="0"/>
            <xs:element name="status" type="xs:string"/>
            <xs:element name="transaction" type="xs:string"/>
            <xs:element name="type" type="xs:string" minOccurs="0"/>
            <xs:element name="subtype" type="xs:string" minOccurs="0"/>
            <xs:element name="category" type="xs:string" minOccurs="0"/>
            <xs:element name="rooms" type="xs:integer" minOccurs="0"/>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="description" type="xs:string" minOccurs="0"/>
            <xs:element name="description_en" type="xs:string" minOccurs="0"/>
            <xs:element name="price" type="xs:decimal" minOccurs="0"/>
            <xs:element name="currency" type="xs:string" minOccurs="0"/>
            <xs:element name="price_unit" type="xs:string" minOccurs="0"/>
            <xs:element name="price_note" type="xs:string" minOccurs="0"/>
            <xs:element name="commission_included" type="xs:boolean" minOccurs="0"/>
            <xs:element name="disposition" type="xs:string" minOccurs="0"/>
            <xs:element name="usable_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="floor_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="built_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="land_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="balcony_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="terrace_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="cellar_area" type="xs:decimal" minOccurs="0"/>
            <xs:element name="floor" type="xs:integer" minOccurs="0"/>
            <xs:element name="total_floors" type="xs:integer" minOccurs="0"/>
            <xs:element name="underground_floors" type="xs:integer" minOccurs="0"/>
            <xs:element name="building_type" type="xs:string" minOccurs="0"/>
            <xs:element name="building_condition" type="xs:string" minOccurs="0"/>
            <xs:element name="ownership" type="xs:string" minOccurs="0"/>
            <xs:element name="energy_class" type="xs:string" minOccurs="0"/>
            <xs:element name="furnished" type="xs:string" minOccurs="0"/>
            <xs:element name="heating_systems" type="heatingSystemsType" minOccurs="0"/>
            <xs:element name="year_built" type="xs:integer" minOccurs="0"/>
            <xs:element name="year_reconstructed" type="xs:integer" minOccurs="0"/>
            <xs:element name="address" type="addressType"/>
            <xs:element name="images" type="imagesType" minOccurs="0"/>
            <xs:element name="detail_url" type="xs:string" minOccurs="0"/>
            <xs:element name="broker" type="brokerType" minOccurs="0"/>
            <xs:element name="agency" type="agencyType" minOccurs="0"/>
            <xs:element name="updated_at" type="xs:string" minOccurs="0"/>
        </xs:all>
    </xs:complexType>

    <!-- `city` alebo `city_part` musí byť vyplnené (XSD to nevie vynútiť bez zložitejšieho vzoru) -->
    <xs:complexType name="addressType">
        <xs:all>
            <xs:element name="country" type="xs:string"/>
            <xs:element name="region" type="xs:string" minOccurs="0"/>
            <xs:element name="district" type="xs:string" minOccurs="0"/>
            <xs:element name="city" type="xs:string" minOccurs="0"/>
            <xs:element name="city_part" type="xs:string" minOccurs="0"/>
            <xs:element name="street" type="xs:string" minOccurs="0"/>
            <xs:element name="postal_code" type="xs:string" minOccurs="0"/>
            <xs:element name="latitude" type="xs:decimal" minOccurs="0"/>
            <xs:element name="longitude" type="xs:decimal" minOccurs="0"/>
            <xs:element name="hide_exact" type="xs:boolean" minOccurs="0"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="heatingSystemsType">
        <xs:sequence>
            <xs:element name="heating_system" type="xs:integer" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="imagesType">
        <xs:sequence>
            <xs:element name="image" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="url" type="xs:string"/>
                    </xs:sequence>
                    <xs:attribute name="order" type="xs:integer" use="optional"/>
                    <xs:attribute name="kind" type="xs:string" use="optional"/>
                    <xs:attribute name="main" type="xs:boolean" use="optional"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="brokerType">
        <xs:all>
            <xs:element name="name" type="xs:string" minOccurs="0"/>
            <xs:element name="email" type="xs:string" minOccurs="0"/>
            <xs:element name="phone" type="xs:string" minOccurs="0"/>
            <xs:element name="web" type="xs:string" minOccurs="0"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="agencyType">
        <xs:all>
            <xs:element name="name" type="xs:string" minOccurs="0"/>
            <xs:element name="ico" type="xs:string" minOccurs="0"/>
        </xs:all>
    </xs:complexType>

</xs:schema>
