<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2019 Norwegian Agency for Public Management and eGovernment (Difi)
  ~
  ~ Licensed under the EUPL, Version 1.1 or – as soon they
  ~ will be approved by the European Commission - subsequent
  ~ versions of the EUPL (the "Licence");
  ~
  ~ You may not use this work except in compliance with the Licence.
  ~
  ~ You may obtain a copy of the Licence at:
  ~
  ~ https://joinup.ec.europa.eu/community/eupl/og_page/eupl
  ~
  ~ Unless required by applicable law or agreed to in
  ~ writing, software distributed under the Licence is
  ~ distributed on an "AS IS" basis,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  ~ express or implied.
  ~ See the Licence for the specific language governing
  ~ permissions and limitations under the Licence.
  -->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xmlns:xmldsig="http://www.w3.org/2000/09/xmldsig#"
           xmlns="urn:fdc:difi.no:2019:bcp:v1:signing"
           targetNamespace="urn:fdc:difi.no:2019:bcp:v1:signing"
           elementFormDefault="qualified">

    <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>

    <xsd:element name="Participant" type="ParticipantType"/>
    <xsd:complexType name="ParticipantType">
        <xsd:sequence>
            <xsd:element name="ParticipantIdentifier" type="IdentifierType"/>
            <xsd:element name="Timestamp" type="xsd:dateTime"/>
            <xsd:element name="ProcessReference" type="ProcessReferenceType" maxOccurs="unbounded"/>
            <xsd:element ref="xmldsig:Signature"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="Process" type="ProcessType"/>
    <xsd:complexType name="ProcessType">
        <xsd:sequence>
            <xsd:element name="ParticipantIdentifier" type="IdentifierType"/>
            <xsd:element name="ProcessIdentifier" type="IdentifierType"/>
            <xsd:element name="Role" type="RoleType"/>
            <xsd:choice>
                <xsd:element name="Date" type="xsd:date"/>
                <xsd:element name="Timestamp" type="xsd:dateTime"/>
            </xsd:choice>
            <xsd:element name="Certificate" type="CertificateType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element ref="xmldsig:Signature"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ProcessReferenceType">
        <xsd:simpleContent>
            <xsd:extension base="IdentifierType">
                <xsd:attribute name="role" type="RoleType" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

    <xsd:complexType name="IdentifierType">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="qualifier" type="xsd:string" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

    <xsd:complexType name="CertificateType">
        <xsd:sequence>
            <xsd:element name="Binary" type="xsd:base64Binary"/>
            <xsd:element name="Interval" type="IntervalType" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="serialNumber" type="xsd:string" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="IntervalType">
        <xsd:attribute name="from" type="xsd:dateTime" use="required"/>
        <xsd:attribute name="to" type="xsd:dateTime"/>
    </xsd:complexType>

    <xsd:simpleType name="RoleType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="REQUEST"/>
            <xsd:enumeration value="RESPONSE"/>
        </xsd:restriction>
    </xsd:simpleType>

</xsd:schema>
