<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="custom-fields">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="custom-field-set" maxOccurs="unbounded" minOccurs="0" type="custom-field-set"/>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="uniqueCustomFieldSetName">
            <xs:selector xpath="custom-field-set"/>
            <xs:field xpath="name"/>
        </xs:unique>
    </xs:element>
    <xs:complexType name="custom-field-set">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="name" type="xs:string"/>
            <xs:element name="label" maxOccurs="unbounded" type="translatableString"/>
            <xs:element name="related-entities" type="entity-list"/>
            <xs:element name="fields" maxOccurs="unbounded" type="custom-field-list"/>
        </xs:choice>
        <xs:attribute type="xs:boolean" name="global" default="false"/>
    </xs:complexType>
    <xs:complexType name="custom-field-list">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="int" type="custom-field-int-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="float" type="custom-field-float-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="text" type="custom-field-text-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="text-area" type="custom-field-text-area-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="bool" type="custom-field-bool-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="datetime" type="custom-field-datetime-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="single-select" type="custom-field-single-select-type" maxOccurs="unbounded"
                        minOccurs="0"/>
            <xs:element name="multi-select" type="custom-field-multi-select-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="single-entity-select" type="custom-field-single-entity-select-type" maxOccurs="unbounded"
                        minOccurs="0"/>
            <xs:element name="multi-entity-select" type="custom-field-multi-entity-select-type" maxOccurs="unbounded"
                        minOccurs="0"/>
            <xs:element name="color-picker" type="custom-field-color-picker-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="media-selection" type="custom-field-media-type" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="price" type="custom-field-price-type" maxOccurs="unbounded" minOccurs="0"/>
        </xs:choice>
    </xs:complexType>
    <xs:group name="custom-field-type">
        <xs:choice>
            <xs:element name="label" maxOccurs="unbounded" type="translatableString"/>
            <xs:element name="help-text" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="required" type="xs:boolean" minOccurs="0" default="false"/>
            <xs:element name="position" type="xs:int" minOccurs="0" default="1"/>
            <xs:element name="allow-customer-write" type="xs:boolean" minOccurs="0" default="false"/>
            <xs:element name="allow-cart-expose" type="xs:boolean" minOccurs="0" default="false"/>
            <xs:element name="include-in-search" type="xs:boolean" minOccurs="0" default="false"/>
        </xs:choice>
    </xs:group>
    <xs:complexType name="custom-field-int-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
            <xs:element name="placeholder" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="steps" type="xs:int" minOccurs="0" default="1"/>
            <xs:element name="min" type="xs:int" minOccurs="0"/>
            <xs:element name="max" type="xs:int" minOccurs="0"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-float-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
            <xs:element name="placeholder" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="steps" type="xs:float" minOccurs="0" default="0.1"/>
            <xs:element name="min" type="xs:float" minOccurs="0"/>
            <xs:element name="max" type="xs:float" minOccurs="0"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-text-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
            <xs:element name="placeholder" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-text-area-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
            <xs:element name="placeholder" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-bool-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-datetime-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-single-select-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
            <xs:element name="placeholder" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="options" type="option-collection"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-multi-select-type">
        <xs:complexContent>
            <xs:extension base="custom-field-single-select-type"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="custom-field-single-entity-select-type">
        <xs:choice maxOccurs="unbounded">
            <xs:choice maxOccurs="unbounded">
                <xs:group ref="custom-field-type"/>
                <xs:element name="placeholder" type="translatableString" minOccurs="0" maxOccurs="unbounded"/>
            </xs:choice>
            <xs:element name="entity" type="xs:string"/>
            <xs:element name="label-property" type="xs:string"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-multi-entity-select-type">
        <xs:complexContent>
            <xs:extension base="custom-field-single-entity-select-type"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="custom-field-color-picker-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-price-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="custom-field-media-type">
        <xs:choice maxOccurs="unbounded">
            <xs:group ref="custom-field-type"/>
        </xs:choice>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>
    <xs:complexType name="entity-list">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="product" type="empty" minOccurs="0"/>
            <xs:element name="order" type="empty" minOccurs="0"/>
            <xs:element name="category" type="empty" minOccurs="0"/>
            <xs:element name="customer" type="empty" minOccurs="0"/>
            <xs:element name="customer_address" type="empty" minOccurs="0"/>
            <xs:element name="media" type="empty" minOccurs="0"/>
            <xs:element name="media_folder" type="empty" minOccurs="0"/>
            <xs:element name="media_folder_configuration" type="empty" minOccurs="0"/>
            <xs:element name="product_manufacturer" type="empty" minOccurs="0"/>
            <xs:element name="sales_channel" type="empty" minOccurs="0"/>
            <xs:element name="landing_page" type="empty" minOccurs="0"/>
            <xs:element name="promotion" type="empty" minOccurs="0"/>
            <xs:element name="product_stream" type="empty" minOccurs="0"/>
            <xs:element name="property_group" type="empty" minOccurs="0"/>
            <xs:element name="property_group_option" type="empty" minOccurs="0"/>
            <xs:element name="product_review" type="empty" minOccurs="0"/>
            <xs:element name="event_action" type="empty" minOccurs="0"/>
            <xs:element name="country" type="empty" minOccurs="0"/>
            <xs:element name="currency" type="empty" minOccurs="0"/>
            <xs:element name="customer_group" type="empty" minOccurs="0"/>
            <xs:element name="delivery_time" type="empty" minOccurs="0"/>
            <xs:element name="document_base_config" type="empty" minOccurs="0"/>
            <xs:element name="language" type="empty" minOccurs="0"/>
            <xs:element name="number_range" type="empty" minOccurs="0"/>
            <xs:element name="payment_method" type="empty" minOccurs="0"/>
            <xs:element name="rule" type="empty" minOccurs="0"/>
            <xs:element name="salutation" type="empty" minOccurs="0"/>
            <xs:element name="shipping_method" type="empty" minOccurs="0"/>
            <xs:element name="tax" type="empty" minOccurs="0"/>
            <xs:element name="unit" type="empty" minOccurs="0"/>
            <xs:element name="newsletter_recipient" type="empty" minOccurs="0"/>
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="empty">
        <xs:complexContent>
            <xs:restriction base="xs:anyType"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="translatableString">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="lang" type="languageCode" default="en-GB"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:simpleType name="languageCode">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z]{2,3}-[A-Z]{2}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="option-collection">
        <xs:sequence>
            <xs:element name="option" type="option" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="option">
        <xs:sequence>
            <xs:element name="name" type="translatableString" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="value" use="required"/>
    </xs:complexType>
</xs:schema>
