<!--
		SIF Infrastructure Specification 3.7

		(January 21, 2025)
		
		Infrastructure Version: 3.7
		
		license: 
		    name: Apache  2.0
        identifier: Apache-2.0
        url: 'https://home.a4l.org/legal/'
	-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sifassociation.org/infrastructure/3.7" targetNamespace="http://www.sifassociation.org/infrastructure/3.7" elementFormDefault="qualified" version="3.7">
  <xs:complexType name="xqueryType">
    <xs:annotation>
      <xs:appinfo>
        <sifChar />
        <privacyRating />
      </xs:appinfo>
      <xs:documentation>This collection defines the entire set of named queries that Consumers may legally issue for execution by Service Providers. A Consumer specifies the ID of a Named XQuery in a Query Request to a specific Service Provider, along with a set of values for any associated script parameters.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="type">
        <xs:annotation>
          <xs:appinfo>
            <sifChar>M</sifChar>
            <privacyRating />
          </xs:appinfo>
          <xs:documentation>Determines if the query may be sent to a data provider or if it requires the extended XQuery mechanism.</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="SINGULAR" />
            <xs:enumeration value="FORMULA" />
            <xs:enumeration value="EXTENDED" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="status">
        <xs:annotation>
          <xs:appinfo>
            <sifChar>M</sifChar>
            <privacyRating />
          </xs:appinfo>
          <xs:documentation>Communicates if the query has been inspected for data hiding and the results of that assessment.</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="PENDING" />
            <xs:enumeration value="APPROVED" />
            <xs:enumeration value="DISALLOWED" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="qualifier" minOccurs="0">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:annotation>
              <xs:appinfo>
                <sifChar>O</sifChar>
                <privacyRating />
              </xs:appinfo>
              <xs:documentation>If status is DISALLOWED this element optionally contains the reason.</xs:documentation>
            </xs:annotation>
            <xs:minLength value="0" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
            <xs:maxLength value="1024" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="description" minOccurs="0">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:annotation>
              <xs:appinfo>
                <sifChar>O</sifChar>
                <privacyRating />
              </xs:appinfo>
              <xs:documentation>Human readable description of the XQuery's intended behavior.</xs:documentation>
            </xs:annotation>
            <xs:maxLength value="1024" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
            <xs:minLength value="0" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="script">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:annotation>
              <xs:appinfo>
                <sifChar>M</sifChar>
                <privacyRating />
              </xs:appinfo>
              <xs:documentation>The text of the XQuery which MAY accept parameters. Usage of the CDATA designation is recommended. An empty value indicates the query is implimented wihtout XQuery or its logic is not disclosed</xs:documentation>
            </xs:annotation>
            <xs:minLength value="0" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="parameters" type="parametersType">
        <xs:annotation>
          <xs:appinfo>
            <sifChar>M</sifChar>
            <privacyRating />
          </xs:appinfo>
          <xs:documentation />
        </xs:annotation>
      </xs:element>
      <xs:element name="returnType" nillable="true" type="xs:anyURI">
        <xs:annotation>
          <xs:appinfo>
            <sifChar>M</sifChar>
            <privacyRating />
          </xs:appinfo>
          <xs:documentation>The fully qualified name of the root element returned by this service. Example: http://www.sifassociation.org/datamodel/na/3.3:students </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="id" use="optional" type="xs:token">
      <xs:annotation>
        <xs:appinfo>
          <sifChar>C</sifChar>
          <privacyRating />
        </xs:appinfo>
        <xs:documentation>The unique ID of the XQuery Template, which is contained in the Query Request URL when this template is being utilized. "Suggested" by the Consumer issuing the create Request, or pre-set in accordance with the binding requirements of a particular SIF release. This is NOT required to be a UUID, and must be provided as the Service Identifier in every Query URL which invokes this Template. Ex: "StudentSnapshot". </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:element name="xquery" type="xqueryType">
    <xs:key name="xqueryKey1">
      <xs:selector xpath="." />
      <xs:field xpath="@id" />
    </xs:key>
  </xs:element>

  <xs:complexType name="xqueryCollectionType">
    <xs:sequence>
      <xs:element name="xquery" type="xqueryType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="xquerys" type="xqueryCollectionType" />

</xs:schema>