<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="order">
        <xsd:complexType>
            <xsd:annotation>
                <xsd:documentation>The order wrapper</xsd:documentation>
            </xsd:annotation>
            <xsd:all>
                <xsd:element name="number">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:minLength value="1"/>
                            <xsd:maxLength value="32"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="currency" default="EUR">
                    <xsd:annotation>
                        <xsd:documentation>
                            Currency code, ISO 4217 formatted
                        </xsd:documentation>
                    </xsd:annotation>
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:minLength value="3"/>
                            <xsd:maxLength value="3"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="date" type="xsd:dateTime">
                    <xsd:annotation>
                        <xsd:documentation>
                            Date formatted in ISO8601 (Y-m-d\TH:i:sP)
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:element>
                <xsd:element name="fees" minOccurs="0">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="fee" maxOccurs="unbounded" type="orderFee"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="billingAddress" type="orderAddress"/>
                <xsd:element name="shippingAddress" type="orderAddress"/>
                <xsd:element name="lines">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="line" maxOccurs="unbounded" type="orderLine"/>
                        </xsd:sequence>
                    </xsd:complexType>
                    <xsd:unique name="lineUnique">
                        <xsd:selector xpath="line"/>
                        <xsd:field xpath="id"/>
                    </xsd:unique>
                </xsd:element>
            </xsd:all>
        </xsd:complexType>
    </xsd:element>
    <xsd:complexType name="orderFee">
        <xsd:all>
            <xsd:element name="type" type="feeType"/>
            <xsd:element name="amount" type="xsd:decimal"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="orderAddress">
        <xsd:all>
            <xsd:element name="salutation" type="genderType"/>
            <xsd:element name="firstName" type="xsd:string"/>
            <xsd:element name="lastName" type="xsd:string"/>
            <xsd:element name="company" minOccurs="0" type="xsd:string"/>
            <xsd:element name="street" type="xsd:string"/>
            <xsd:element name="houseNumber" type="xsd:int"/>
            <xsd:element name="houseNumberExtension" minOccurs="0" type="xsd:string"/>
            <xsd:element name="addressNote" minOccurs="0" type="xsd:string"/>
            <xsd:element name="zipCode" type="xsd:string"/>
            <xsd:element name="city" type="xsd:string"/>
            <xsd:element name="state" minOccurs="0" type="xsd:string"/>
            <xsd:element name="country">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:minLength value="2"/>
                        <xsd:maxLength value="2"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="phone" minOccurs="0" type="xsd:string"/>
            <xsd:element name="taxNumber" minOccurs="0" type="xsd:string"/>
            <xsd:element name="email">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:pattern value="[^@]+@[^\.]+\..+"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="orderLine">
        <xsd:all>
            <xsd:element name="id" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Your own reference to this orderline.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="productIdentifiers">
                <xsd:annotation>
                    <xsd:documentation>
                        At least one product identifier is required to identify the product in this order.
                    </xsd:documentation>
                </xsd:annotation>
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="identifier" maxOccurs="unbounded" type="productIdentifier"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="productTitle" type="xsd:string"/>
            <xsd:element name="quantity">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:unsignedInt">
                        <xsd:minExclusive value="0"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="individualProductPrice" type="xsd:decimal">
                <xsd:annotation>
                    <xsd:documentation>
                        The individual product price.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="fees" minOccurs="0">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="fee" maxOccurs="unbounded" type="orderFee"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="productIdentifier">
        <xsd:all>
            <xsd:element name="type" type="identifierType"/>
            <xsd:element name="value" type="xsd:string"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:simpleType name="genderType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="m">
                <xsd:annotation>
                    <xsd:documentation>
                        Male
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:enumeration>
            <xsd:enumeration value="f">
                <xsd:annotation>
                    <xsd:documentation>
                        Female
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:enumeration>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="feeType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="commission"/>
            <xsd:enumeration value="shipping"/>
            <xsd:enumeration value="transaction"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="identifierType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="ID"/>
            <xsd:enumeration value="IDENTIFIER"/>
            <xsd:enumeration value="EAN"/>
            <xsd:enumeration value="SKU"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>
