<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="config">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="extension_attributes" type="extension_attributesType" minOccurs="1"
                            maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation>Main schema element. Extended Attributes</xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="attributeType">
        <xs:sequence>
            <xs:element name="resources" type="resourcesType" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="join" type="joinType" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="code" use="required"/>
        <xs:attribute type="xs:string" name="type" use="required"/>
    </xs:complexType>
    <xs:complexType name="extension_attributesType">
        <xs:sequence>
            <xs:element type="attributeType" name="attribute" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="for" use="required"/>
    </xs:complexType>
    <xs:complexType name="resourcesType">
        <xs:sequence>
            <xs:element name="resource" type="resourceType" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="selectFieldType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="column" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="joinType">
        <xs:sequence>
            <xs:element type="selectFieldType" name="field" maxOccurs="unbounded" minOccurs="1"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="reference_table" use="required"/>
        <xs:attribute type="xs:string" name="join_on_field" use="required"/>
        <xs:attribute type="xs:string" name="reference_field" use="required"/>
    </xs:complexType>
    <xs:complexType name="resourceType">
        <xs:attribute name="ref" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value=".+(, ?.+)*"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
</xs:schema>
