<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.0">

  <xs:annotation>
    <xs:documentation>
      DX1 Legacy Inventory on Demand feed schema.

      This compatibility schema documents the structure emitted by the legacy
      DX1 Inventory on Demand XML export. It is intentionally more permissive
      than the current DX1 inventory schema and should not be interpreted as a
      new contractual feed standard.

      The schema has no target namespace because legacy documents use
      unqualified element names. Element order is significant.
    </xs:documentation>
  </xs:annotation>

  <xs:simpleType name="uuidType">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="currencyCodeType">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{3}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="inventory" type="inventoryType"/>

  <xs:complexType name="inventoryType">
    <xs:sequence>
      <xs:element name="vendor-code" type="xs:string">
        <xs:annotation>
          <xs:documentation>Feed vendor identifier. Legacy DX1 feeds normally use DX1.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="dealer" type="dealerType"/>
      <xs:element name="listings" type="listingsType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="dealerType">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="address-1" type="xs:string" minOccurs="0"/>
      <xs:element name="city" type="xs:string" minOccurs="0"/>
      <xs:element name="state" type="xs:string" minOccurs="0"/>
      <xs:element name="postal-code" type="xs:string" minOccurs="0"/>
      <xs:element name="country" type="xs:string" minOccurs="0"/>
      <xs:element name="phone" type="xs:string" minOccurs="0"/>
      <xs:element name="toll-free-phone" type="xs:string" minOccurs="0"/>
      <xs:element name="fax" type="xs:string" minOccurs="0"/>
      <xs:element name="email" type="xs:string" minOccurs="0"/>
      <xs:element name="website-url" type="xs:anyURI" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="listingsType">
    <xs:sequence>
      <xs:element name="listing" type="listingType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="listingType">
    <xs:sequence>
      <xs:element name="type" type="xs:string">
        <xs:annotation>
          <xs:documentation>Legacy DX1 product type, such as Cruiser, Utility SxS, or ATV Utility.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="condition" type="xs:string">
        <xs:annotation>
          <xs:documentation>Observed values include NEW and USED.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="miles" type="xs:nonNegativeInteger" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Optional odometer value. Units are miles.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="listing-id" type="uuidType"/>
      <xs:element name="model-year" type="xs:gYear"/>
      <xs:element name="color-primary" type="xs:string"/>
      <xs:element name="stock-number" type="xs:string"/>
      <xs:element name="description-short" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Optional short marketing description. May contain plain text.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="description-long" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Optional long description. Legacy values may contain HTML serialized as text or CDATA.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="listing-url" type="xs:anyURI"/>
      <xs:element name="model" type="xs:string"/>
      <xs:element name="category" type="xs:string"/>
      <xs:element name="manufacturer" type="xs:string"/>
      <xs:element name="vin" type="xs:string">
        <xs:annotation>
          <xs:documentation>Vehicle identifier. Depending on product category, this may be a 17-character VIN or a shorter HIN/serial identifier.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="listing-photos" type="listingPhotosType"/>
      <xs:element name="location" type="locationType"/>
      <xs:element name="price" type="priceType"/>
      <xs:element name="specifications" type="specificationsType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="listingPhotosType">
    <xs:sequence>
      <xs:element name="photo" type="photoType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="photoType">
    <xs:sequence>
      <xs:element name="url" type="xs:anyURI">
        <xs:annotation>
          <xs:documentation>Media URL. Legacy feeds may include image URLs and video URLs in this collection.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="display-order" type="xs:positiveInteger"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="locationType">
    <xs:sequence>
      <xs:element name="address-1" type="xs:string"/>
      <xs:element name="postal-code" type="xs:string"/>
      <xs:element name="city" type="xs:string"/>
      <xs:element name="state" type="xs:string"/>
      <xs:element name="country" type="xs:string"/>
      <xs:element name="phone" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="priceType">
    <xs:sequence>
      <xs:element name="currency" type="currencyCodeType"/>
      <xs:element name="text" type="xs:decimal">
        <xs:annotation>
          <xs:documentation>Numeric listing price. The legacy element name is text even though observed values are decimal amounts.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="specificationsType">
    <xs:sequence>
      <xs:element name="specification" type="specificationType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="specificationType">
    <xs:sequence>
      <xs:element name="specification-name" type="xs:string"/>
      <xs:element name="specification-value" type="xs:string">
        <xs:annotation>
          <xs:documentation>Specification text. Legacy values may contain HTML serialized as text or CDATA.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
