﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.woodpecker-it.com/xmlns/wpit-export-8.0.xsd"
		   elementFormDefault="qualified"
		   xmlns="http://www.woodpecker-it.com/xmlns/wpit-export-8.0.xsd"
		   xmlns:mstns="http://www.woodpecker-it.com/xmlns/wpit-export-8.0.xsd"
		   xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <!--
    Version history:

    Woodpecker Issue Tracker 7.3.0  Added attachment IDs to data value
    Woodpecker Issue Tracker 7.1.0  Added data type "UrlList"
    Woodpecker Issue Tracker 6.4.6  Added attribute "lastUpdate" to the complex type "Issue" and changed documentation
                                    for attribute "timeStamp" on the same complex type to make the difference between
                                    the two clear.
    Woodpecker Issue Tracker 5.4    Initial schema version

    -->

	<!-- PART I: Root -->

	<!-- The document element -->

	<xs:element name="export" type="Export"/>

	<xs:complexType name="Export">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				Document element of a WPIT export
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="selectionListDefs" type="SelectionListDefs" minOccurs="1" maxOccurs="1"/>
			<xs:element name="statusDefs" type="StatusDefs" minOccurs="1" maxOccurs="1"/>
			<xs:element name="fieldDefs" type="FieldDefs" minOccurs="1" maxOccurs="1"/>
			<xs:element name="issues" type="Issues" minOccurs="1" maxOccurs="1"/>
		</xs:sequence>
	</xs:complexType>

	<!-- PART II: Main structural types -->

	<!-- Selection list definitions -->

	<xs:complexType name="SelectionListDefs">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A list of selection list definitions
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="selectionListDef" type="SelectionListDef" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="SelectionListDef">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A selection list definition
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="item" type="SelectionListDefItem" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attribute name="fieldName" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Name of the field definition for which the selection list definition will provide the values
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:complexType name="SelectionListDefItem">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A single selection list item
			</xs:documentation>
		</xs:annotation>

		<xs:attribute name="text" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Text of the selection list definition item
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<!-- Status definitions -->

	<xs:complexType name="StatusDefs">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A list of status definitions
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="statusDef" type="StatusDef" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="StatusDef">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A status definition
			</xs:documentation>
		</xs:annotation>

		<xs:attribute name="text" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Text (and also key) of the status definition
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<!-- Field definitions -->

	<xs:complexType name="FieldDefs">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A list of field definitions
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="fieldDef" type="FieldDef" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="FieldDef">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A field definition
			</xs:documentation>
		</xs:annotation>

		<xs:attribute name="id" type="WPIT_ID" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					ID of the field definition
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="name" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Name of the field
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="type" type="FieldType" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Type of the field
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="history" type="xs:boolean" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Wether the field supports a history
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="length" type="xs:positiveInteger" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Length of the field
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="statusRelation" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Status definition to which the field is related
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:simpleType name="FieldType">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				Field type
			</xs:documentation>
		</xs:annotation>

		<xs:restriction base="xs:string">
			<xs:enumeration value="Text"/>
			<xs:enumeration value="TextSelection"/>
			<xs:enumeration value="Int"/>
			<xs:enumeration value="IntSelection"/>
			<xs:enumeration value="Float"/>
			<xs:enumeration value="FloatSelection"/>
			<xs:enumeration value="Date"/>
			<xs:enumeration value="Attachment"/>
			<xs:enumeration value="SelectionList"/>
			<xs:enumeration value="ProjectMember"/>
			<xs:enumeration value="ProjectMemberAutomail"/>
			<xs:enumeration value="LinkList"/>
			<xs:enumeration value="Boolean"/>
			<xs:enumeration value="UrlList"/>
		</xs:restriction>
	</xs:simpleType>

	<!-- Issues -->

	<xs:complexType name="Issues">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A list of issues
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="issue" type="Issue" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="Issue">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				An issue
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="statusHistory" type="StatusHistory" minOccurs="0" maxOccurs="1"/>
			<xs:element name="field" type="Field" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>

		<xs:attribute name="id" type="WPIT_ID" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					ID of the issue
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="parent" type="WPIT_IDREF" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					bugID of the parent issue
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="project" type="xs:int" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					ID of the project to which the issue belongs
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="status" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Status of the issue
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="user" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Name of the user that created the issue
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="timeStamp" type="TimeStampSeparated" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Date and time of the creation of the issue. Format: YYYY-MM-DD hh:mm:ss
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="visibility" type="xs:boolean" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Wether the issue is visible or not
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="bugID" type="xs:int" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Bug ID of the issue
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="lastUpdate" type="TimeStampSeparated" use="optional">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Date and time of the last change to the issue. Format: YYYY-MM-DD hh:mm:ss
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:complexType name="Field">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A field of an issue
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="history" type="FieldHistory" minOccurs="0" maxOccurs="1"/>
		</xs:sequence>

		<xs:attribute name="fieldDef" type="WPIT_IDREF" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Reference to the field definition of the field
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="value" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation xml:lang="en">
					Textual representation of the value of the field
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
        <xs:attribute name="attachment-ids" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    Comma-separated list of attachment IDs (for use with the Export API).
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
	</xs:complexType>

	<!-- PART III: Helper types -->

	<!-- Histories -->

	<xs:complexType name="FieldHistory">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				History of a field value
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="value" type="FieldHistoryValue" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="FieldHistoryValue">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A particular version in the history of a field value
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="text" type="xs:string">
				<xs:annotation>
					<xs:documentation xml:lang="en">
						Text of the field value of the particular field change
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="timeStamp" type="TimeStampCompact">
				<xs:annotation>
					<xs:documentation xml:lang="en">
						Date and time at which the particular field change happened. Format: YYYYMMDDhhmmss
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="userName" type="xs:string">
				<xs:annotation>
					<xs:documentation xml:lang="en">
						Username of the user that made the particular field change
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="StatusHistory">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				History of an issue status
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="value" type="StatusHistoryValue" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="StatusHistoryValue">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				A particular version in the history of an issue status
			</xs:documentation>
		</xs:annotation>

		<xs:sequence>
			<xs:element name="text" type="xs:string">
				<xs:annotation>
					<xs:documentation xml:lang="en">
						Key of the status of the particular status change
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="timeStamp" type="TimeStampCompact">
				<xs:annotation>
					<xs:documentation xml:lang="en">
						Date and time at which the particular status change happened. Format: YYYYMMDDhhmmss
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="userName" type="xs:string">
				<xs:annotation>
					<xs:documentation xml:lang="en">
						Username of the user that made the particular status change
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:complexType>

	<!-- WPIT IDs and references to IDs (Cannot use xs:ID because it does not allow numerical values) -->

	<xs:simpleType name="WPIT_ID">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				Positive numerical ID
			</xs:documentation>
		</xs:annotation>

		<xs:restriction base="xs:positiveInteger"/>
	</xs:simpleType>

	<xs:simpleType name="WPIT_IDREF">
		<xs:annotation>
			<xs:documentation xml:lang="en">
				Reference to a positive numerical ID
			</xs:documentation>
		</xs:annotation>

		<xs:restriction base="xs:positiveInteger"/>
	</xs:simpleType>

	<xs:simpleType name="TimeStampCompact">
		<xs:restriction base="xs:string">
			<xs:pattern value="[0-9]{4}(0[0-9]|1[0-2])([0-2][0-9]|3[0-1])([0-1][0-9]|2[0-3])([0-5][0-9])([0-5][0-9])"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:simpleType name="TimeStampSeparated">
		<xs:restriction base="xs:string">
			<xs:pattern value="[0-9]{4}-(0[0-9]|1[0-2])-([0-2][0-9]|3[0-1]) ([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])"/>
		</xs:restriction>
	</xs:simpleType>

</xs:schema>
