<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="deviceNameParameter_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="$id"/>
      <xs:enumeration value="$index"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="componentNameParameter_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="$index"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="channelNameParameter_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="$id"/>
      <xs:enumeration value="$index"/>
      <xs:enumeration value="$deviceIndex"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="dataPointNameParameter_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="$id"/>
      <xs:enumeration value="$index"/>
      <xs:enumeration value="$deviceIndex"/>
      <xs:enumeration value="$channelIndex"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="valueEvent_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="always"/>
      <xs:enumeration value="onChange"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="defaultValueInit_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="value"/>
      <xs:enumeration value="none"/>
      <xs:enumeration value="readOnStart"/>
      <xs:enumeration value="always"/>
      <xs:enumeration value="firstChangeEvent"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="fieldType_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="KNX"/>
      <xs:enumeration value="GDS"/>
      <xs:enumeration value="Internal"/>
      <xs:enumeration value="Timer"/>
      <xs:enumeration value="Sequence"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="startIdType_t">
    <xs:restriction base="xs:string">
      <xs:enumeration value="fix"/>
      <xs:enumeration value="relDevice"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="fieldPropertiesKnx_t">
    <xs:sequence>
      <xs:element name="readGroupAddress" minOccurs="0"/>
      <xs:element name="writeGroupAddress" minOccurs="0"/>
      <xs:element name="listenerGroupAddress" minOccurs="0"/>
      <xs:element name="dpt" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="fieldPropertiesGds_t">
    <xs:sequence>
      <xs:element name="address" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="fieldPropertiesInternal_t">
    <xs:sequence>
      <xs:element name="value" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="metaData_t">
    <xs:attribute name="Key" type="xs:string"/>
    <xs:attribute name="Value" type="xs:string"/>
  </xs:complexType>
  <xs:complexType name="parameterSet_t">
    <xs:attribute name="Set" type="xs:string"/>
    <xs:attribute name="Key" type="xs:string"/>
    <xs:attribute name="Value" type="xs:string"/>
  </xs:complexType>

  <xs:complexType name="dataPoint_t" mixed="true">
      <xs:sequence>
        <xs:element name="nameParameter" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="param" type="dataPointNameParameter_t" maxOccurs="unbounded"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="description" minOccurs="0"/>
        <xs:element name="access" minOccurs="0">
          <xs:complexType>
            <xs:attribute name="WriteAccess" type="xs:boolean" use="optional"/>
            <xs:attribute name="ReadAccess" type="xs:boolean" use="optional"/>
            <xs:attribute name="Eventing" type="xs:boolean" use="optional"/>
          </xs:complexType>
        </xs:element>
        <xs:element name="valueDefinitions" minOccurs="0">
          <xs:complexType>
            <xs:attribute name="ValueEvent" type="valueEvent_t" use="optional"/>
            <xs:attribute name="CachedValueTimeout" type="xs:unsignedInt"  use="optional"/>
            <xs:attribute name="DefaultValueInit" type="defaultValueInit_t" use="optional"/>
            <xs:attribute name="DefaultValue" type="xs:string" use="optional"/>
            <xs:attribute name="PollingInterval" type="xs:unsignedInt" use="optional"/>
          </xs:complexType>
        </xs:element>
        <xs:element name="fieldProperties" minOccurs="0">
          <xs:complexType>
            <xs:choice>
              <xs:element name="knx" type="fieldPropertiesKnx_t"/>
              <xs:element name="gds" type="fieldPropertiesGds_t"/>
              <xs:element name="internal" type="fieldPropertiesInternal_t"/>
            </xs:choice>
          </xs:complexType>
        </xs:element>
        <xs:element name="metaData" type="metaData_t" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="Name" type="xs:string" use="optional"/>
      <xs:attribute name="ObjectType" type="xs:string" use="optional"/>
      <xs:attribute name="FieldHandlerName" type="xs:string" use="optional"/>
      <xs:attribute name="StartId" type="xs:unsignedInt" use="optional"/>
      <xs:attribute name="Index" type="xs:unsignedInt" use="optional"/>
      <xs:attribute name="Enable" type="xs:boolean" use="optional"/>
      <xs:attribute name="Visible" type="xs:boolean" use="optional"/>
      <xs:attribute name="Count" type="xs:unsignedInt" use="optional"/>
      <xs:attribute name="ValueType" type="xs:string" use="optional"/>
      <xs:attribute name="ValueSubType" type="xs:string" use="optional"/>
      <xs:attribute name="SaveValue" type="xs:boolean" use="optional"/>
      <xs:attribute name="PermitReadFromBus" type="xs:boolean" use="optional"/>
      <xs:attribute name="GpaHint" type="xs:string" use="optional"/>
      <!-- ASA/WKA: If we need to allow 'any' unforeseen attribute use: xs:anyAttribute processContents="skip"/ -->
  </xs:complexType>

  <xs:complexType name="channel_t" mixed="true">
    <xs:sequence>
      <xs:element name="nameParameter" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="param" type="channelNameParameter_t" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="description" minOccurs="0"/>
      <xs:element name="defaultDPIndex" minOccurs="0">
        <xs:complexType>
          <xs:attribute name="Read" type="xs:unsignedInt" use="optional"/>
          <xs:attribute name="Write" type="xs:unsignedInt" use="optional"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="dataPoint" type="dataPoint_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="metaData" type="metaData_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="parameterSet" type="parameterSet_t" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="TypeURN" type="xs:string" use="required"/>
    <xs:attribute name="FieldType" type="xs:string" use="required"/>
    <xs:attribute name="FieldHandlerName" type="xs:string" use="optional"/>
    <xs:attribute name="StartId" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="StartIdType" type="startIdType_t" use="optional"/>
    <xs:attribute name="Index" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="Enable" type="xs:boolean" use="optional"/>
    <xs:attribute name="Visible" type="xs:boolean" use="optional"/>
    <xs:attribute name="Count" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="IdIntervalOffset" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="GpaHint" type="xs:string" use="optional"/>
    <xs:attribute name="ResetOnGpaCommisioning" type="xs:boolean" use="optional"/>
    <!-- ASA/WKA: If we need to allow 'any' unforeseen attribute use: xs:anyAttribute processContents="skip"/ -->
  </xs:complexType>

  <!-- Static component instances -->
  <xs:complexType name="staticComponent_t" mixed="true">
    <xs:sequence>
      <xs:element name="nameParameter" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="param" type="componentNameParameter_t" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="description" minOccurs="0"/>
      <xs:element name="metaData" type="metaData_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="parameterSet" type="parameterSet_t" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="TypeURN" type="xs:string" use="optional"/>
    <xs:attribute name="FieldHandlerName" type="xs:string" use="optional"/>
    <xs:attribute name="StartId" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="StartIdType" type="startIdType_t" use="optional"/>
    <xs:attribute name="Index" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="Enable" type="xs:boolean" use="optional"/>
    <xs:attribute name="Visible" type="xs:boolean" use="optional"/>
    <xs:attribute name="Count" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="IdIntervalOffset" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="GpaHint" type="xs:string" use="optional"/>
    <xs:attribute name="ResetOnGpaCommisioning" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <!-- Dynamic component instances (will be instanciated by GpaConfigLib) -->
  <xs:complexType name="component_t" mixed="true">
    <xs:sequence>
      <xs:element name="description" minOccurs="0"/>
      <xs:element name="nameParameter" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="param" type="componentNameParameter_t" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="metaData" type="metaData_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="parameterSet" type="parameterSet_t" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="TypeURN" type="xs:string" use="optional"/>
    <xs:attribute name="FieldHandlerName" type="xs:string" use="optional"/>
    <xs:attribute name="SystemType" type="xs:string" use="optional"/>
    <xs:attribute name="ResetOnGpaCommisioning" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <xs:complexType name="parameter_t">
    <xs:sequence>
      <xs:element name="handler" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
    <xs:anyAttribute processContents="skip"/>
  </xs:complexType>

  <xs:complexType name="parameters_t">
    <xs:sequence>
      <xs:element name="parameter" type="parameter_t" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="device_t" mixed="true">
    <xs:sequence>
      <xs:element name="nameParameter" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="param" type="deviceNameParameter_t" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="description" minOccurs="0"/>
      <xs:element name="channel" type="channel_t" maxOccurs="unbounded"/>
      <xs:element name="staticComponent" type="staticComponent_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="component" type="component_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="metaData" type="metaData_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="parameterSet" type="parameterSet_t" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="parameters" type="parameters_t" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="Type" type="xs:string" use="required"/>
    <xs:attribute name="StartId" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="Enable" type="xs:boolean" use="optional"/>
    <xs:attribute name="Visible" type="xs:boolean" use="optional"/>
    <xs:attribute name="Count" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="IdIntervalOffset" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="GpaHint" type="xs:string" use="optional"/>
    <xs:attribute name="GpaLocatable" type="xs:boolean" use="optional"/>
    <xs:attribute name="SystemType" type="xs:string" use="optional"/>
    <!-- ASA/WKA: If we need to allow 'any' unforeseen attribute use: xs:anyAttribute processContents="skip"/ -->
  </xs:complexType>

  <xs:element name="deviceDefinition">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="description" type="xs:string"/>
        <xs:element name="devices" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="device" type="device_t" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="channels" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="channel" type="channel_t" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="dataPoints" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="dataPoint" type="dataPoint_t" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="Name" type="xs:string" use="required"/>
      <xs:attribute name="Version" type="xs:string" use="optional"/>
      <xs:attribute name="GpaHint" type="xs:string" use="optional"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
