<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.cablelabs.com/namespaces/safi/xsd/iam/1.1"
    xmlns:com="http://www.cablelabs.com/namespaces/safi/xsd/com/1.1"
    targetNamespace="http://www.cablelabs.com/namespaces/safi/xsd/iam/1.1" elementFormDefault="qualified"
    attributeFormDefault="unqualified" version="1.0">
    <xs:import namespace="http://www.cablelabs.com/namespaces/safi/xsd/com/1.1"
        schemaLocation="http://www.cablelabs.com/namespaces/safi/xsd/com/v1.1/CL-SaFI-COM-1.1.0.xsd"/>
    <xs:annotation>
        <xs:documentation>
            <b>Copyright (C) 2008-2010, Cable Television Laboratories, Inc.</b>
            <b>SaFI Interactive Application Messaging Interface XML Schema Version 1.1.-1</b>            
        </xs:documentation>
        <xs:documentation> AppMsg is the wrapper element containing each message. It contains
            exactly one message header along with one or more Application Message Blocks.
        </xs:documentation>
    </xs:annotation>
    <xs:element name="AppMsg" type="ApplicationMessageType"/>

    <xs:complexType name="ApplicationMessageType">
        <xs:sequence>
            <xs:group ref="ApplicationMessageHeaderGroup"/>
            <xs:element name="AppMsgBlock" type="ApplicationMessageBlockType" minOccurs="1"
                maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ApplicationMessageBlockType">
        <xs:annotation>
            <xs:documentation> This is the payload of the AppMsg. Each message must contain 1 or
                more AppMsgBlocks. Each AppMsgBlock will have an inheirited PEID from the Applcation
                Message Header along with an EPSID for unique identification. The AppMsgBlock can
                contain multiple AppReportBlocks each with its own EventID for identification.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="EPSID" type="com:EpsidType"/>
            <xs:element name="AppReportBlock" type="ApplicationReportBlockType" minOccurs="1"
                maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ApplicationReportBlockType">
        <xs:annotation>
            <xs:documentation> AppReportBlocks are the finest level of reporting. They allow
                reporting at the EventID level. </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="EventID" type="com:EventIDType" minOccurs="0"/>
            <xs:element name="UserInput" type="com:UserInputType" minOccurs="0"/>
            <xs:element name="Parameters" type="com:ParametersType" minOccurs="0"/>
        </xs:sequence>
        <xs:attributeGroup ref="com:RelativeTimeAttributeGroup"/>
    </xs:complexType>

    <xs:simpleType name="UnitIDType">
        <xs:annotation>
            <xs:documentation> UnitID represents the device unique identifier. This could be the
                device MAC address. </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="12"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:group name="ApplicationMessageHeaderGroup">
        <xs:annotation>
            <xs:documentation> This group contains the data elements representing the Header of ab
                Application Message. The header info appears exactly once in each message. It is
                constructed from the following elements, each contracted to save space: MS -
                MinSchemaVersionType (Replaces ProtocolVersion as the common schema/protocol
                versioning element across all interfaces) UID - Unit ID PEID - Programming Event ID
                GID - Geographic ID/Code T - Timestamp (Timestamp is a reference time in UTC
                (YYYY-MM-DDThh:mm:ss.mm) that is sent with each message so that each Event carried
                in an Application Message can reference times in a more compact format specifically
                as an offset of the reference time. Note: The common TimestampType from
                CommonTypes.xsd is not used here as Applcaition messaging requires a more compact
                timing scheme. </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="Version" type="com:VersionType"/>
            <xs:element name="UnitID" type="UnitIDType"/>
            <xs:element name="GeoCode" type="com:GeographicCodeType"/>
            <xs:element name="PEID" type="com:PeidType"/>
            <xs:element name="Timestamp" type="xs:dateTime"/>
            <xs:element name="ApplicationInfo" minOccurs="0">
                <xs:complexType>
                    <xs:attributeGroup ref="com:ApplicationDefinitionAttributeGroup"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="DecoderInfo" type="DecoderInfoType" minOccurs="0"/>
            <xs:element name="ContextInfo" type="ContextInfoType" minOccurs="0"/>
        </xs:sequence>
    </xs:group>

    <xs:complexType name="ContextInfoType">
        <xs:annotation>
            <xs:documentation>Context information related to the instance of the application</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="ContextDesignators" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="contextDesignatorType" type="xs:int" use="required"/>
                    <xs:attribute name="contextDesignatorValue" type="xs:string" use="required"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="ProgramDesignators" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="programType" type="xs:int" use="required"/>
                    <xs:attribute name="programValue" type="xs:int" use="required"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="MediaDesignator" minOccurs="0">
                <xs:complexType>
                    <xs:attribute name="mediaDesignatorType" type="xs:int" use="required"/>
                    <xs:attribute name="mediaDesignatorValue" type="xs:string" use="required"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="PositionalDesignator" minOccurs="0">
                <xs:complexType>
                    <xs:sequence minOccurs="0">
                        <xs:choice>
                            <xs:element name="TemporalPositionOffset" type="xs:int"/>
                            <xs:element name="TemporalPositionUTC" type="xs:dateTime"/>
                            <xs:element name="TemporalPositionNPT" type="xs:string"/>
                        </xs:choice>
                        <xs:element name="DirectionSpeedDesignator" minOccurs="0">
                            <xs:complexType>
                                <xs:attribute name="direction" type="xs:string" use="required"/>
                                <xs:attribute name="speed" type="xs:int" use="required"/>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="ContextType" type="xs:int" use="required"/>
        <xs:attribute name="Description" type="xs:string" use="optional"/>
    </xs:complexType>
    
    <xs:complexType name="DecoderInfoType">
        <xs:annotation>
            <xs:documentation>Information about the encoder sending the message</xs:documentation>
        </xs:annotation>
        <xs:attribute name="HWManufacturer" type="xs:string" use="optional"/>
        <xs:attribute name="HWModel" type="xs:string" use="optional"/>
        <xs:attribute name="HWVersionMajor" type="xs:string" use="optional"/>
        <xs:attribute name="HWVersionMinor" type="xs:string" use="optional"/>
        <xs:attribute name="SWManufacturer" type="xs:string" use="optional"/>
        <xs:attribute name="SWModel" type="xs:string" use="optional"/>
        <xs:attribute name="SWVersionMajor" type="xs:string" use="optional"/>
        <xs:attribute name="SWVersionMinor" type="xs:string" use="optional"/>
    </xs:complexType>

</xs:schema>

