<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:thing-description="https://openhab.org/schemas/thing-description/v1.0.0"
	xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
	targetNamespace="https://openhab.org/schemas/thing-description/v1.0.0">

	<xs:import namespace="https://openhab.org/schemas/config-description/v1.0.0"
		schemaLocation="https://openhab.org/schemas/config-description-1.0.0.xsd"/>

	<xs:element name="thing-descriptions">
		<xs:complexType>
			<xs:choice minOccurs="1" maxOccurs="unbounded">
				<xs:element name="thing-type" type="thing-description:thingType"/>
				<xs:element name="bridge-type" type="thing-description:bridgeType"/>
				<xs:element name="channel-type" type="thing-description:channelType"/>
				<xs:element name="channel-group-type" type="thing-description:channelGroupType"/>
			</xs:choice>
			<xs:attribute name="bindingId" type="config-description:idRestrictionPattern" use="required"/>
		</xs:complexType>
	</xs:element>

	<xs:complexType name="thingType">
		<xs:sequence>
			<xs:element name="supported-bridge-type-refs" type="thing-description:supportedBridgeTypeRefs"
				minOccurs="0"/>
			<xs:element name="label" type="xs:string"/>
			<xs:element name="description" type="xs:string" minOccurs="0"/>
			<xs:element name="category" type="xs:string" minOccurs="0"/>
			<xs:choice minOccurs="0">
				<xs:element name="channels" type="thing-description:channels"/>
				<xs:element name="channel-groups" type="thing-description:channelGroups"/>
			</xs:choice>
			<xs:element name="properties" type="thing-description:properties" minOccurs="0"/>
			<xs:element name="representation-property" type="xs:string" minOccurs="0"/>
			<xs:choice minOccurs="0">
				<xs:element name="config-description" type="config-description:configDescription"/>
				<xs:element name="config-description-ref" type="config-description:configDescriptionRef"/>
			</xs:choice>
		</xs:sequence>
		<xs:attribute name="id" type="config-description:idRestrictionPattern" use="required"/>
		<xs:attribute name="listed" type="xs:boolean" default="true" use="optional"/>
		<xs:attribute name="extensible" type="thing-description:namespaceIdListRestrictionPattern" use="optional"/>
	</xs:complexType>

	<xs:simpleType name="namespaceIdListRestrictionPattern">
		<xs:restriction base="xs:string">
			<xs:pattern value="[A-Za-z0-9\-_.]+(,( )?[A-Za-z0-9\-_.]+)*"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:complexType name="bridgeType">
		<xs:complexContent>
			<xs:extension base="thing-description:thingType"/>
		</xs:complexContent>
	</xs:complexType>

	<xs:simpleType name="auto-update-policy">
		<xs:restriction base="xs:string">
			<xs:enumeration value="veto"/>
			<xs:enumeration value="default"/>
			<xs:enumeration value="recommend"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:complexType name="channelType">
		<xs:sequence>
			<xs:element name="item-type" type="thing-description:itemType" minOccurs="0"/>
			<xs:element name="kind" type="xs:string" minOccurs="0"/>
			<xs:element name="label" type="xs:string"/>
			<xs:element name="description" type="xs:string" minOccurs="0"/>
			<xs:element name="category" type="xs:string" minOccurs="0"/>
			<xs:element name="tags" type="thing-description:tags" minOccurs="0"/>
			<xs:element name="state" type="thing-description:state" minOccurs="0"/>
			<xs:element name="command" type="thing-description:command" minOccurs="0"/>
			<xs:element name="event" type="thing-description:event" minOccurs="0"/>
			<xs:element name="autoUpdatePolicy" type="thing-description:auto-update-policy" minOccurs="0"/>
			<xs:choice minOccurs="0">
				<xs:element name="config-description" type="config-description:configDescription"/>
				<xs:element name="config-description-ref" type="config-description:configDescriptionRef"/>
			</xs:choice>
		</xs:sequence>
		<xs:attribute name="id" type="config-description:idRestrictionPattern" use="required"/>
		<xs:attribute name="advanced" type="xs:boolean" default="false" use="optional"/>
		<xs:attribute name="system" type="xs:boolean" default="false" use="optional"/>
	</xs:complexType>

	<xs:complexType name="channelGroupType">
		<xs:sequence>
			<xs:element name="label" type="xs:string"/>
			<xs:element name="description" type="xs:string" minOccurs="0"/>
			<xs:element name="category" type="xs:string" minOccurs="0"/>
			<xs:element name="channels" type="thing-description:channels" minOccurs="0"/>
		</xs:sequence>
		<xs:attribute name="id" type="config-description:idRestrictionPattern" use="required"/>
	</xs:complexType>

	<xs:complexType name="supportedBridgeTypeRefs">
		<xs:sequence>
			<xs:element name="bridge-type-ref" type="thing-description:bridgeTypeRef" minOccurs="1"
				maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="bridgeTypeRef">
		<xs:attribute name="id" type="config-description:idRestrictionPattern" use="required"/>
	</xs:complexType>

	<xs:complexType name="channels">
		<xs:sequence>
			<xs:element name="channel" type="thing-description:channel" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:simpleType name="namespaceIdRestrictionPattern">
		<xs:restriction base="xs:string">
			<xs:pattern value="[A-Za-z0-9\-_.]+"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:complexType name="channel">
		<xs:sequence>
			<xs:element name="label" type="xs:string" minOccurs="0"/>
			<xs:element name="description" type="xs:string" minOccurs="0"/>
			<xs:element name="properties" type="thing-description:properties" minOccurs="0"/>
			<xs:element name="autoUpdatePolicy" type="thing-description:auto-update-policy" minOccurs="0"/>
		</xs:sequence>
		<xs:attribute name="id" type="config-description:idRestrictionPattern" use="required"/>
		<xs:attribute name="typeId" type="thing-description:namespaceIdRestrictionPattern" use="required"/>
	</xs:complexType>

	<xs:complexType name="channelGroups">
		<xs:sequence>
			<xs:element name="channel-group" type="thing-description:channelGroup" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="channelGroup">
		<xs:sequence>
			<xs:element name="label" type="xs:string" minOccurs="0"/>
			<xs:element name="description" type="xs:string" minOccurs="0"/>
		</xs:sequence>
		<xs:attribute name="id" type="config-description:idRestrictionPattern" use="required"/>
		<xs:attribute name="typeId" type="config-description:idRestrictionPattern" use="required"/>
	</xs:complexType>

	<xs:simpleType name="itemTypeName">
		<xs:restriction base="xs:string">
			<xs:enumeration value="Call"/>
			<xs:enumeration value="Color"/>
			<xs:enumeration value="Contact"/>
			<xs:enumeration value="DateTime"/>
			<xs:enumeration value="Dimmer"/>
			<xs:enumeration value="Group"/>
			<xs:enumeration value="Image"/>
			<xs:enumeration value="Location"/>
			<xs:enumeration value="Number"/>
			<xs:enumeration value="Number:Acceleration"/>
			<xs:enumeration value="Number:AmountOfSubstance"/>
			<xs:enumeration value="Number:Angle"/>
			<xs:enumeration value="Number:Area"/>
			<xs:enumeration value="Number:ArealDensity"/>
			<xs:enumeration value="Number:CatalyticActivity"/>
			<xs:enumeration value="Number:Currency"/>
			<xs:enumeration value="Number:DataAmount"/>
			<xs:enumeration value="Number:DataTransferRate"/>
			<xs:enumeration value="Number:Density"/>
			<xs:enumeration value="Number:Dimensionless"/>
			<xs:enumeration value="Number:ElectricCapacitance"/>
			<xs:enumeration value="Number:ElectricCharge"/>
			<xs:enumeration value="Number:ElectricConductance"/>
			<xs:enumeration value="Number:ElectricConductivity"/>
			<xs:enumeration value="Number:ElectricCurrent"/>
			<xs:enumeration value="Number:ElectricInductance"/>
			<xs:enumeration value="Number:ElectricPotential"/>
			<xs:enumeration value="Number:ElectricResistance"/>
			<xs:enumeration value="Number:EmissionIntensity"/>
			<xs:enumeration value="Number:Energy"/>
			<xs:enumeration value="Number:EnergyPrice"/>
			<xs:enumeration value="Number:Force"/>
			<xs:enumeration value="Number:Frequency"/>
			<xs:enumeration value="Number:Illuminance"/>
			<xs:enumeration value="Number:Intensity"/>
			<xs:enumeration value="Number:Length"/>
			<xs:enumeration value="Number:LuminousFlux"/>
			<xs:enumeration value="Number:LuminousIntensity"/>
			<xs:enumeration value="Number:MagneticFlux"/>
			<xs:enumeration value="Number:MagneticFluxDensity"/>
			<xs:enumeration value="Number:Mass"/>
			<xs:enumeration value="Number:Power"/>
			<xs:enumeration value="Number:Pressure"/>
			<xs:enumeration value="Number:RadiationDoseAbsorbed"/>
			<xs:enumeration value="Number:RadiationDoseEffective"/>
			<xs:enumeration value="Number:RadiationSpecificActivity"/>
			<xs:enumeration value="Number:RadioactiveActivity"/>
			<xs:enumeration value="Number:SolidAngle"/>
			<xs:enumeration value="Number:Speed"/>
			<xs:enumeration value="Number:Temperature"/>
			<xs:enumeration value="Number:Time"/>
			<xs:enumeration value="Number:Volume"/>
			<xs:enumeration value="Number:VolumetricFlowRate"/>
			<xs:enumeration value="Player"/>
			<xs:enumeration value="Rollershutter"/>
			<xs:enumeration value="String"/>
			<xs:enumeration value="Switch"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:complexType name="itemType">
		<xs:simpleContent>
			<xs:extension base="thing-description:itemTypeName">
				<xs:attribute name="unitHint" type="xs:string"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>

	<xs:complexType name="tags">
		<xs:sequence>
			<xs:element name="tag" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="state">
		<xs:sequence>
			<xs:element name="options" type="thing-description:options" minOccurs="0"/>
		</xs:sequence>
		<xs:attribute name="min" type="xs:decimal" use="optional"/>
		<xs:attribute name="max" type="xs:decimal" use="optional"/>
		<xs:attribute name="step" type="xs:decimal" use="optional"/>
		<xs:attribute name="pattern" type="xs:string" use="optional"/>
		<xs:attribute name="readOnly" type="xs:boolean" default="false" use="optional"/>
	</xs:complexType>

	<xs:complexType name="event">
		<xs:sequence>
			<xs:element name="options" type="thing-description:options" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="options">
		<xs:sequence>
			<xs:element name="option" type="thing-description:option" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="command">
		<xs:sequence>
			<xs:element name="options" type="thing-description:options" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="option">
		<xs:simpleContent>
			<xs:extension base="xs:string">
				<xs:attribute name="value" type="xs:string" use="required"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>

	<xs:complexType name="properties">
		<xs:sequence>
			<xs:element name="property" type="thing-description:property" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="property">
		<xs:simpleContent>
			<xs:extension base="xs:string">
				<xs:attribute name="name" type="xs:string" use="required"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>
</xs:schema>
