<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * XSD for an XML, composed as result of merging all config files with PDF settings
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="config" type="configType"/>

    <xs:complexType name="configType">
        <xs:all>
            <xs:element name="renderers" type="renderersType" minOccurs="0">
                <xs:unique name="uniquePageRenderer">
                    <xs:selector xpath="page"/>
                    <xs:field xpath="@type"/>
                </xs:unique>
            </xs:element>
            <xs:element name="totals" type="totalsType" minOccurs="0">
                <xs:unique name="uniqueTotalItem">
                    <xs:selector xpath="total"/>
                    <xs:field xpath="@name"/>
                </xs:unique>
            </xs:element>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="renderersType">
        <xs:sequence>
            <xs:element name="page" type="pageType" minOccurs="0" maxOccurs="unbounded">
                <xs:unique name="uniqueProductTypeRenderer">
                    <xs:selector xpath="renderer"/>
                    <xs:field xpath="@product_type"/>
                </xs:unique>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="pageType">
        <xs:sequence>
            <xs:element name="renderer" type="rendererType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="rendererType">
        <xs:simpleContent>
            <xs:extension base="classNameType">
                <xs:attribute name="product_type" type="xs:string" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="classNameType">
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Z][a-zA-Z\d]*(\\[A-Z][a-zA-Z\d]*)*" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="totalsType">
        <xs:sequence>
            <xs:element name="total" type="totalItemType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="totalItemType">
        <xs:all>
            <xs:element name="title" type="totalTitleType"/>
            <xs:element name="source_field" type="fieldType"/>
            <xs:element name="title_source_field" type="fieldType" minOccurs="0"/>
            <xs:element name="font_size" type="xs:positiveInteger" minOccurs="0"/>
            <xs:element name="display_zero" type="xs:boolean" minOccurs="0"/>
            <xs:element name="sort_order" type="xs:nonNegativeInteger" minOccurs="0"/>
            <xs:element name="model" type="classNameType" minOccurs="0"/>
            <xs:element name="amount_prefix" type="xs:string" minOccurs="0"/>
        </xs:all>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="totalTitleType">
        <xs:simpleContent>
            <xs:extension base="nonEmptyString">
                <xs:attribute name="translate" type="xs:boolean"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="nonEmptyString">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="fieldType">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z0-9_]+" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
