<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="RESOURCE_PROFILE">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="HEADER" type="HEADERType"/>
                <xs:element name="BODY" type="BODYType"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="HEADERType">
        <xs:all>
            <xs:element name="RESOURCE_IDENTIFIER" type="RESOURCE_IDENTIFIERType"/>
            <xs:element name="RESOURCE_TYPE" type="RESOURCE_TYPEType"/>
            <xs:element name="RESOURCE_KIND" type="RESOURCE_KINDType"/>
            <xs:element name="RESOURCE_URI" type="RESOURCE_URIType"/>
            <xs:element name="DATE_OF_CREATION" type="DATE_OF_CREATIONType"/>
            <xs:element name="PROTOCOL" type="xs:string"/>
        </xs:all>
    </xs:complexType>
    <xs:complexType name="BODYType">
        <xs:sequence>
            <xs:element name="CONFIGURATION" type="CONFIGURATION"/>
            <xs:element name="STATUS" type="STATUS"/>
            <xs:element name="QOS" type="QOS"/>
            <xs:element name="SECURITY_PARAMETERS" type="xs:string"/>
            <xs:element name="BLACKBOARD" type="BLACKBOARD"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="BLACKBOARD">
        <xs:sequence>
            <xs:element name="LAST_REQUEST" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="LAST_RESPONSE" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="MESSAGE" type="MESSAGE" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CONFIGURATION">
        <xs:all>
            <!-- Typology of the datasource: repository, aggregator, etc. -->
            <xs:element name="DATASOURCE_TYPE" type="xs:string" minOccurs="0"/>
            <!-- Original identifier of the datasource. Ex. <DATASOURCE_ORIGINAL_ID 
				provenance="OpenDoar">openDoar ID</DATASOURCE_ORIGINAL_ID> It corresponds 
				to the old schema EXTRA_FIELD with key='OpenAireDataSourceId' -->
            <xs:element name="DATASOURCE_ORIGINAL_ID" type="DATASOURCE_ORIGINAL_IDType" minOccurs="0"/>

            <!-- True if this datasource is aggregated by an aggregator -->
            <xs:element name="DATASOURCE_AGGREGATED" minOccurs="0" type="xs:boolean"/>

            <!-- If DATASOURCE_AGGREGATED is true, then DATASOURCE_AGGREGATOR_ID contains 
				the resource identifier of the profile of the aggregator. -->
            <xs:element name="DATASOURCE_AGGREGATOR_ID" type="xs:string" minOccurs="0"/>
            <!-- Names of environments with services that are allowed to manage this 
				datasource. For example, the environment for Slovenia repositories is SLOVENIA, 
				while the environment for repositories joining the OpenAire project is OpenAire. 
				This list of environment name supercedes the old schema EXTRA_FIELD element 
				with key='aggregatorName' -->
            <xs:element name="ENVIRONMENTS" type="ENVIRONMENTSType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="TYPOLOGY" type="xs:string"/>
            <xs:element name="MAX_SIZE_OF_DATASTRUCTURE" type="xs:integer"/>
            <xs:element name="AVAILABLE_DISKSPACE" type="xs:string"/>
            <xs:element name="MAX_NUMBER_OF_DATASTRUCTURE" type="xs:integer"/>
            <xs:element name="OFFICIAL_NAME" type="xs:string"/>
            <xs:element name="ENGLISH_NAME" type="xs:string"/>
            <xs:element name="ICON_URI" type="xs:string"/>
            <xs:element name="COUNTRY" type="xs:string"/>
            <xs:element name="LOCATION" type="LOCATION"/>
            <xs:element name="REPOSITORY_WEBPAGE" type="xs:string"/>
            <xs:element name="REPOSITORY_INSTITUTION" type="xs:string"/>
            <xs:element name="ADMIN_INFO" type="xs:string"/>
            <xs:element name="INTERFACES" type="INTERFACES"/>
            <xs:element name="REGISTERED_BY" type="xs:string" minOccurs="0"/>
            <xs:element name="EXTRA_FIELDS" type="EXTRA_FIELDS" minOccurs="0"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="DATASOURCE_ORIGINAL_IDType">
        <xs:annotation>
            <xs:documentation>Type for the datasource original identifier.
				The
				original id is not the D-Net profile identifier, but an id that
				identifies the datasource itself in the outside world.
				The provenance
				attribute references to the organisation,institution,
				etc, where the
				id had been taken from.
				For example, the profile for a repository
				that is in OpenDoar will have
				its opendoar id with provenance
				'OpenDoar'.
				This field should be used instead of the old schema
				EXTRA_FIELD with key='OpenAireDataSourceId'</xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="provenance"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="ACCESSPROTOCOLDATACOLLType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:anyAttribute processContents="lax"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="LAST_UPDATEType">
        <xs:attribute name="value" type="xs:dateTime" use="required"/>
    </xs:complexType>
    <xs:complexType name="LOCATION">
        <xs:all>
            <xs:element name="LONGITUDE" type="xs:double"/>
            <xs:element name="LATITUDE" type="xs:double"/>
            <xs:element name="TIMEZONE">
                <xs:simpleType>
                    <xs:restriction base="xs:double">
                        <xs:pattern value="-?[0-9]*(\.[05])?"/>
                        <xs:minInclusive value="-12.0"/>
                        <xs:maxInclusive value="12.0"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:all>
    </xs:complexType>
    <xs:complexType mixed="true" name="STATUS">
        <xs:all>
            <xs:element name="HANDLED_DATASTRUCTURE" type="xs:integer" minOccurs="0"/>
            <xs:element name="USED_DISKSPACE" type="xs:integer" minOccurs="0"/>
            <xs:element name="NUMBER_OF_OBJECTS" type="xs:integer"/>
            <xs:element name="LAST_UPDATE" type="LAST_UPDATEType" minOccurs="0"/>
        </xs:all>
    </xs:complexType>
    <xs:simpleType name="ACTION_STATUS">
        <xs:restriction base="xs:string">
            <xs:enumeration value="DONE"/>
            <xs:enumeration value="ONGOING"/>
            <xs:enumeration value="FAILED"/>
            <xs:enumeration value="WAITING"/>
            <xs:enumeration value="ASSIGNED"/>
        </xs:restriction>
    </xs:simpleType>
   
    <xs:complexType name="INTERFACE">
        <xs:sequence>
            <xs:element name="ACCESS_PROTOCOL">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:anyAttribute processContents="lax"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="BASE_URL" type="xs:string"/>
           
            
            <xs:element name="INTERFACE_EXTRA_FIELD" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="name" use="required" type="xs:string"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>

        <!-- The attributes id, typology, group have been imported from the Datacoll Type
			to keep track of the correspondence: interface <-> datacoll  -->

        <!-- id of the interface. -->
        <xs:attribute name="id" type="xs:string" use="required"/>

        <!-- label of the interface. -->
        <xs:attribute name="label" type="xs:string" use="required"/>

        <!-- brief information/description about the interface -->
        <xs:attribute name="typology" type="xs:string"/>

        <!-- 
        	Indicates if this interface is related with almost one workflow
        -->
        <xs:attribute name="compliance" type="xs:string" use="required"/>

        <!-- 
        	Indicates if this interface is related with almost one workflow
         -->

        <xs:attribute name="active" type="xs:boolean" use="required"/>

        <!-- 
        	Indicates if this interface is related with almost one workflow
         -->
        <xs:attribute name="removable" type="xs:boolean" use="required"/>
        
		<!-- 
        	Indicates the description of the data provided by the interface (typical values are metadata, file::WoS, file::PDF, file::EuropePMC)  
		-->
        <xs:attribute name="contentDescription" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="ENVIRONMENTSType">
        <xs:annotation>
            <xs:documentation>The list of environments that can manage this
				datasource.
				An environment identifies a set of services of one or
				more D-Net
				installations.
				The element ENVIRONMENT supercedes the
				EXTRA_FIELD element with
				key='aggregatorName'.</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="ENVIRONMENT" type="xs:string" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="INTERFACES">
        <xs:sequence>
            <xs:element name="INTERFACE" type="INTERFACE" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="EXTRA_FIELDS">
        <xs:sequence>
            <xs:element name="FIELD" type="FieldType" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="FieldType">
        <xs:all>
            <xs:element name="key" type="xs:string"/>
            <xs:element name="value" type="xs:string"/>
        </xs:all>
    </xs:complexType>
    <xs:complexType name="RESOURCE_TYPEType">
        <xs:attribute name="value" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="RepositoryServiceResourceType"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
    <xs:complexType name="RESOURCE_URIType">
        <xs:attribute name="value" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="RESOURCE_KINDType">
        <xs:attribute name="value" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="RepositoryServiceResources"/>
                    <xs:enumeration value="PendingRepositoryResources"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
    <xs:complexType name="RESOURCE_IDENTIFIERType">
        <xs:attribute name="value" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="DATE_OF_CREATIONType">
        <xs:attribute name="value" type="xs:dateTime" use="required"/>
    </xs:complexType>
    <xs:complexType name="QOS">
        <xs:sequence>
            <xs:element name="AVAILABILITY" type="xs:string"/>
            <xs:element name="CAPACITY" type="xs:string"/>
            <xs:element name="RESPONSE_TIME" type="xs:string" minOccurs="0"/>
            <xs:element name="THROUGHPUT" type="xs:double"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="PARAMETERS">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="name" type="xs:string" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="MESSAGE">
        <xs:sequence>
            <xs:element name="ACTION" type="ACTION"/>
            <xs:element name="PARAMETERS" type="PARAMETERS" maxOccurs="unbounded"/>
            <xs:element name="ACTION_STATUS" type="ACTION_STATUS"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:simpleType name="ACTION">
        <xs:restriction base="xs:string">
            <xs:enumeration value="CREATE"/>
            <xs:enumeration value="DELETE"/>
            <xs:enumeration value="UPDATE"/>
            <xs:enumeration value="MANAGE"/>
            <xs:enumeration value="RELEASE"/>
            <xs:enumeration value="CANCEL"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
