<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:include schemaLocation="taz_file.xsd" />

    <xsd:element name="net" type="netType">
        <xsd:key name="edgeKey">
            <xsd:selector xpath="edge"/>
            <xsd:field xpath="@id"/>
        </xsd:key>
        <xsd:keyref name="edgeKeyRefFrom" refer="edgeKey">
            <xsd:selector xpath="connection"/>
            <xsd:field xpath="@from"/>
        </xsd:keyref>
        <xsd:keyref name="edgeKeyRefTo" refer="edgeKey">
            <xsd:selector xpath="connection"/>
            <xsd:field xpath="@to"/>
        </xsd:keyref>
    </xsd:element>

    <xsd:complexType name="netType">
        <xsd:sequence>
            <xsd:element name="location" type="locationType" minOccurs="1" maxOccurs="1"/>
            <xsd:element name="edge" type="edgeType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="tlLogic" type="tlLogicType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="junction" type="junctionType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="connection" type="connectionType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="prohibition" type="prohibitionType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="roundabout" type="roundaboutType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="taz" type="tazType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="version">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern value="\d+.\d+"></xsd:pattern>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="edgeType">
        <xsd:sequence>
            <xsd:element name="lane" type="laneType" minOccurs="1" maxOccurs="63"/>
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:string" use="required"/>
        <xsd:attribute name="function" use="optional">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="normal"/>
                    <xsd:enumeration value="internal"/>
                    <xsd:enumeration value="connector"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="from" type="xsd:string"/>
        <xsd:attribute name="to" type="xsd:string"/>
        <xsd:attribute name="name" type="xsd:string" use="optional"/>
        <xsd:attribute name="priority" type="xsd:integer" use="optional"/>
        <xsd:attribute name="length" type="positiveFloatType" use="optional"/>
        <xsd:attribute name="type" type="xsd:string" use="optional"/>
        <xsd:attribute name="shape" type="shapeType" use="optional"/>
        <xsd:attribute name="spreadType" use="optional">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="center"/>
                    <xsd:enumeration value="right"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="laneType">
        <xsd:attribute name="id" type="xsd:string" use="required"/>
        <xsd:attribute name="index" type="xsd:nonNegativeInteger" use="required"/>
        <xsd:attribute name="allow" type="xsd:string" use="optional"/>
        <xsd:attribute name="disallow" type="xsd:string" use="optional"/>
        <xsd:attribute name="prefer" type="xsd:string" use="optional"/>
        <xsd:attribute name="speed" type="positiveFloatType" use="required"/>
        <xsd:attribute name="length" type="positiveFloatType" use="required"/>
        <xsd:attribute name="endOffset" type="positiveFloatType" use="optional"/>
        <xsd:attribute name="width" type="positiveFloatType" use="optional"/>
        <xsd:attribute name="shape" type="shapeType" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="junctionType">
        <xsd:sequence>
            <xsd:element name="request" type="requestType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:string" use="required"/>
        <xsd:attribute name="x" type="xsd:float" use="required"/>
        <xsd:attribute name="y" type="xsd:float" use="required"/>
        <xsd:attribute name="z" type="xsd:float" use="optional"/>
        <xsd:attribute name="type" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="traffic_light"/>
                    <xsd:enumeration value="right_before_left"/>
                    <xsd:enumeration value="priority"/>
                    <xsd:enumeration value="dead_end"/>
                    <xsd:enumeration value="unregulated"/>
                    <xsd:enumeration value="internal"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="incLanes" type="xsd:string" use="required"/>
        <xsd:attribute name="intLanes" type="xsd:string" use="required"/>
        <xsd:attribute name="shape" type="shapeType" use="optional"/>
    </xsd:complexType>

    <xsd:complexType name="requestType">
        <xsd:attribute name="index" type="xsd:nonNegativeInteger" use="required"/>
        <xsd:attribute name="response" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern
                        value="[01]+">
                    </xsd:pattern>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="foes" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern
                        value="[01]+">
                    </xsd:pattern>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="cont" type="boolType" use="optional"/>
    </xsd:complexType>

    <xsd:complexType name="connectionType">
        <xsd:attribute name="from" type="xsd:string" use="required"/>
        <xsd:attribute name="to" type="xsd:string" use="required"/>
        <xsd:attribute name="fromLane" type="xsd:nonNegativeInteger" use="required"/>
        <xsd:attribute name="toLane" type="xsd:nonNegativeInteger" use="required"/>
        <xsd:attribute name="pass" type="boolType" use="optional"/>
        <xsd:attribute name="via" type="xsd:string" use="optional"/>
        <xsd:attribute name="tl" type="xsd:string" use="optional"/>
        <xsd:attribute name="linkIndex" type="xsd:nonNegativeInteger" use="optional"/>
        <xsd:attribute name="dir" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="s"/>
                    <xsd:enumeration value="t"/>
                    <xsd:enumeration value="l"/>
                    <xsd:enumeration value="r"/>
                    <xsd:enumeration value="L"/>
                    <xsd:enumeration value="R"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="state" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="M"/>
                    <xsd:enumeration value="m"/>
                    <xsd:enumeration value="o"/>
                    <xsd:enumeration value="="/>
                    <xsd:enumeration value="-"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="prohibitionType">
        <xsd:attribute name="prohibitor" type="xsd:string" use="required"/>
        <xsd:attribute name="prohibited" type="xsd:string" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="roundaboutType">
        <xsd:attribute name="nodes" type="xsd:string" use="required"/>
        <xsd:attribute name="edges" type="xsd:string" use="required"/>
    </xsd:complexType>

</xsd:schema>
