<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:tpt="http://www.atsc.org/XMLSchemas/iss/tpt/1"
    xmlns:nrt="http://www.atsc.org/XMLSchemas/nrt/2012/1"
    targetNamespace="http://www.atsc.org/XMLSchemas/iss/tpt/1" elementFormDefault="qualified"
    version="1.0">
    <import namespace="http://www.atsc.org/XMLSchemas/nrt/2012/1" schemaLocation="SG1.0.xsd"/>
    <annotation>
        <documentation> [ATSC boilerplate goes here] </documentation>
    </annotation>

    <!-- GLOBAL ELEMENTS -->
    <annotation>
        <documentation> TPT -- TDO Parameters Table -- contains properties of TDOs used in a
            segment, including properties of the events targeting the TDOs </documentation>
    </annotation>
    <element name="TPT" type="tpt:TptType"/>

    <annotation>
        <documentation> AMT -- Activation Messages Table element -- contains list of activation
            messages for a segment </documentation>
    </annotation>
    <element name="AMT" type="tpt:AmtType"/>

    <annotation>
        <documentation> UrlList-- URL List element -- contains list of URLs of interest to receivers
        </documentation>
    </annotation>
    <element name="UrlList" type="tpt:UrlListType"/>

    <!-- TYPE DEFINITIONS -->
    <complexType name="TptType">
        <sequence>
            <element name="Capabilities" type="nrt:CapabilitiesType" minOccurs="0"/>
            <element name="LiveTrigger" type="tpt:LiveTriggerType" minOccurs="0"/>
            <element name="TDO" type="tpt:TDOType" maxOccurs="unbounded"/>
        </sequence>
        <attribute name="majorProtocolVersion" type="tpt:nibble" use="optional" default="1"/>
        <attribute name="minorProtocolVersion" type="tpt:nibble" use="optional" default="0"/>
        <attribute name="id" type="anyURI"/>
        <attribute name="tptVersion" type="unsignedByte"/>
        <attribute name="expireDate" type="dateTime" use="optional"/>
        <attribute name="updatingTime" type="unsignedShort" use="optional"/>
        <attribute name="serviceID" type="unsignedShort" use="optional"/>
        <attribute name="baseURL" type="anyURI" use="optional"/>
    </complexType>

    <complexType name="AppBoundaryType">
        <sequence>
            <element name="OriginURL" type="anyURI" maxOccurs="unbounded"/>
        </sequence>
    </complexType>

    <complexType name="LiveTriggerType">
        <attribute name="URL" type="anyURI"/>
        <attribute name="pollPeriod" type="unsignedByte" use="optional"/>
    </complexType>

    <complexType name="TDOType">
        <sequence>
            <element name="URL" maxOccurs="unbounded">
                <complexType>
                    <simpleContent>
                        <extension base="anyURI">
                            <attribute name="entry" type="boolean" use="optional"/>
                        </extension>
                    </simpleContent>
                </complexType>
            </element>
            <element name="Capabilities" type="nrt:CapabilitiesType" minOccurs="0"/>
            <element name="ApplicationBoundary" type="tpt:AppBoundaryType" minOccurs="0"/>
            <element name="ContentItem" type="tpt:ContentItemType" minOccurs="0"
                maxOccurs="unbounded"/>
            <element name="Event" type="tpt:EventType" maxOccurs="unbounded"/>
        </sequence>
        <attribute name="appId" type="unsignedShort"/>
        <attribute name="appType" type="tpt:nibble" use="optional"/>
        <attribute name="appName" type="string" use="optional"/>
        <attribute name="globalID" type="anyURI" use="optional"/>
        <attribute name="appVersion" type="unsignedByte" use="optional"/>
        <attribute name="cookieSpace" type="unsignedByte" use="optional" default="0"/>
        <attribute name="frequencyOfUse" type="tpt:nibble" use="optional"/>
        <attribute name="expireDate" type="dateTime" use="optional"/>
        <attribute name="testTDO" type="boolean" use="optional"/>
        <attribute name="availInternet" type="boolean" use="optional" default="true"/>
        <attribute name="availBroadcast" type="boolean" use="optional" default="true"/>
    </complexType>

    <complexType name="ContentItemType">
        <sequence>
            <element name="URL" maxOccurs="unbounded">
                <complexType>
                    <simpleContent>
                        <extension base="anyURI">
                            <attribute name="entry" type="boolean" use="optional"/>
                        </extension>
                    </simpleContent>
                </complexType>
            </element>
        </sequence>
        <attribute name="updatesAvail" type="boolean" use="optional"/>
        <attribute name="pollPeriod" type="unsignedByte" use="optional"/>
        <attribute name="size"  use="optional">
            <simpleType>
                <restriction base="unsignedInt">
                    <maxInclusive value="16777215"/>
                </restriction>
            </simpleType>
        </attribute>
        <attribute name="availInternet" type="boolean" use="optional" default="true"/>
        <attribute name="availBroadcast" type="boolean" use="optional" default="true"/>
    </complexType>

    <complexType name="EventType">
        <sequence>
            <element name="Data" minOccurs="0" maxOccurs="unbounded">
                <complexType>
                    <simpleContent>
                        <extension base="base64Binary">
                            <attribute name="dataID" type="unsignedShort"/>
                        </extension>
                    </simpleContent>
                </complexType>
            </element>
        </sequence>
        <attribute name="eventId" type="unsignedShort"/>
        <attribute name="action" type="string"/>
        <attribute name="destination" type="unsignedByte" use="optional"/>
        <attribute name="diffusion" type="unsignedByte" use="optional"/>
    </complexType>

    <complexType name="AmtType">
        <sequence>
            <element name="Activation" minOccurs="0" maxOccurs="unbounded">
                <complexType>
                    <attribute name="targetTDO" type="unsignedShort"/>
                    <attribute name="targetEvent" type="unsignedShort"/>
                    <attribute name="targetData" type="unsignedShort"/>
                    <attribute name="startTime" type="tpt:mtType"/>
                    <attribute name="endtime" type="tpt:mtType" use="optional"/>
                </complexType>
            </element>
        </sequence>
        <attribute name="majorProtocolVersion" type="tpt:nibble" use="optional"/>
        <attribute name="minorProtocolVersion" type="tpt:nibble" use="optional"/>
        <attribute name="segmentid" type="anyURI"/>
        <attribute name="beginMT" type="tpt:mtType" use="optional"/>
    </complexType>

    <complexType name="UrlListType">
        <sequence>
            <element name="TptUrl" type="anyURI" minOccurs="0" maxOccurs="unbounded"/>
            <element name="NrtSignalingUrl" type="anyURI" minOccurs="0"/>
            <element name="UrsUrl" type="anyURI" minOccurs="0"/>
            <element name="PdiUrl" type="anyURI" minOccurs="0"/>
        </sequence>
    </complexType>

    <simpleType name="mtType">
        <restriction base="hexBinary">
            <maxLength value="4"/>
        </restriction>
    </simpleType>

    <simpleType name="nibble">
        <restriction base="unsignedByte">
            <maxInclusive value="15"/>
        </restriction>
    </simpleType>


</schema>
