<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * This schema should be applied for validation of merged router.xml file
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="config">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="router" minOccurs="1" maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation>
                            Router collects routes, parses request and performs matching of request to route.
                        </xs:documentation>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:choice>
                                <xs:element name="route" minOccurs="1" maxOccurs="unbounded" type="routeType">
                                    <xs:unique name="uniqueModuleName">
                                        <xs:annotation>
                                            <xs:documentation>Module name should be unique for route</xs:documentation>
                                        </xs:annotation>
                                        <xs:selector xpath="module" />
                                        <xs:field xpath="@name" />
                                    </xs:unique>
                                </xs:element>
                            </xs:choice>
                        </xs:sequence>
                        <xs:attribute name="id" use="required" type="routerIdType" />
                    </xs:complexType>
                    <xs:unique name="uniqueRouteId">
                        <xs:annotation>
                            <xs:documentation>Route id should be unique</xs:documentation>
                        </xs:annotation>
                        <xs:selector xpath="route" />
                        <xs:field xpath="@id" />
                    </xs:unique>
                    <xs:unique name="uniqueRouteFrontName">
                        <xs:annotation>
                            <xs:documentation>Route front name should be unique</xs:documentation>
                        </xs:annotation>
                        <xs:selector xpath="route" />
                        <xs:field xpath="@frontName" />
                    </xs:unique>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="uniqueRouterId">
            <xs:annotation>
                <xs:documentation>Router id should be unique in file</xs:documentation>
            </xs:annotation>
            <xs:selector xpath="router" />
            <xs:field xpath="@id" />
        </xs:unique>
    </xs:element>

    <xs:simpleType name="routerIdType">
        <xs:annotation>
            <xs:documentation>
                Unique router identifier.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9\-_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="routeType">
        <xs:annotation>
            <xs:documentation>
                Route declares requests to process with desired priority and points a module to perform it.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:choice>
                <xs:element name="module" minOccurs="1" maxOccurs="unbounded" type="moduleType" />
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="id" use="required" type="routeIdType" />
        <xs:attribute name="frontName" use="required" type="routeFrontNameType" />
    </xs:complexType>

    <xs:simpleType name="routeIdType">
        <xs:annotation>
            <xs:documentation>
                Unique route identifier.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="moduleType">
        <xs:annotation>
            <xs:documentation>
                Module is subscribed to process request with corresponding route front name.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="name" use="required" type="moduleNameType" />
        <xs:attribute name="before" use="optional" type="beforeAfterType" />
        <xs:attribute name="after" use="optional" type="beforeAfterType" />
    </xs:complexType>

    <xs:simpleType name="moduleNameType">
        <xs:annotation>
            <xs:documentation>
                Module name. For example, Magento_User.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="beforeAfterType">
        <xs:annotation>
            <xs:documentation>
                Attributes "before" and "after" help you to  specify a priority of routes matching.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="routeFrontNameType">
        <xs:annotation>
            <xs:documentation>
                URL key associated with route.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_\-]{1,}" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
