<?xml version="1.0" encoding="UTF-8"?>
<schema
    xmlns:tns="http://minameddelanden.gov.se/schema/Recipient/v4"
    xmlns:commonv4="http://minameddelanden.gov.se/schema/Common/v4"
    xmlns:authorityv4="http://minameddelanden.gov.se/schema/Authority/v4"
    xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://minameddelanden.gov.se/schema/Recipient/v4"
    elementFormDefault="qualified"
    version="4.0">

    <import namespace="http://minameddelanden.gov.se/schema/Common/v4" schemaLocation="Common.xsd"/>
    <import namespace="http://minameddelanden.gov.se/schema/Authority/v4" schemaLocation="Authority.xsd"/>

    <annotation>
        <documentation xml:lang="en">Common datatype and element definitions for user and recipient.</documentation>
    </annotation>

    <complexType name="reachabilityStatusType">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Information om en mottagare.</documentation>
        </annotation>
        <sequence>
            <element name="accountStatus" type="tns:accountStatusType">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Anger om mottagaren har ett konto i FAR samt adressen
                        till mottagarens brevlådeoperatör.
                    </documentation>
                </annotation>
            </element>
            <element name="senderAccepted" type="boolean">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Anger om mottagaren accepterar elektroniska utskick
                        av avsändaren.
                    </documentation>
                </annotation>
            </element>
            <element name="lastSenderAcceptChange" type="dateTime" minOccurs="0">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Tidpunkt för senaste ändring av godkännande av
                        elektroniska utskick för aktuell avsändare
                    </documentation>
                </annotation>
            </element>
        </sequence>
    </complexType>

    <complexType name="accountStatusType">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Kontokontroll och adresser för en viss mottagare.</documentation>
        </annotation>
        <sequence>
            <element ref="commonv4:recipientId">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Mottagaridentitet.</documentation>
                </annotation>
            </element>
            <element name="accountType" type="tns:accountType">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Anger om konto finns i FAR och i så fall av
                        vilken typ.
                    </documentation>
                </annotation>
            </element>
            <element name="pending" type="boolean">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Kontots nuvarande status, ’true’ om en pågående
                        kontoregistrering finns.
                    </documentation>
                </annotation>
            </element>
            <element ref="commonv4:serviceSupplierId" minOccurs="0">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Info om eventuell brevlådeoperatör. Är
                        ’null’ om konto saknas.
                    </documentation>
                </annotation>
            </element>
            <element name="lastRegistration" type="dateTime" minOccurs="0">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Tidpunkt för senaste kontoregistrering i FAR. Kontot kan
                        ha varit avregistrerat och registrerats på nytt. Så mottagaren kan ha funnit i
                        FAR även innan denna tidpunkt.
                    </documentation>
                </annotation>
            </element>
        </sequence>
    </complexType>

    <simpleType name="accountType">
        <annotation>
            <documentation xml:lang="en">This describes the type of the account.</documentation>
            <documentation xml:lang="sv">Definerade kontotyper.</documentation>
        </annotation>
        <restriction base="string">
            <enumeration value="Secure">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Användaridentitet verifierad med e-legitimation.</documentation>
                </annotation>
            </enumeration>
            <enumeration value="Anonymous">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Anonymt så kallat lågnivåkonto, användarnamn och lösenord.
                    </documentation>
                </annotation>
            </enumeration>
            <enumeration value="Not">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Konto saknas i FAR.</documentation>
                </annotation>
            </enumeration>
        </restriction>
    </simpleType>

    <simpleType name="requestType">
        <annotation>
            <documentation xml:lang="en">Type of request, can either be Create or Delete.
                This may seem a bit redundant when this element is used as input
                in register/deRegister operations, but the element is also used as output
                in the getPendingAccountRequest operation.
            </documentation>
            <documentation xml:lang="sv">Typ av operation, det kan antingen vara Create eller
                Delete. Detta kan tyckas överflödigt då det finns separata operationer för
                Register och DeRegister, men denna datatyp är återkommande i svarsmeddelandet för
                getPendingAccountRequst-operationen, där följande värden har en betydande mening.
            </documentation>
        </annotation>
        <restriction base="string">
            <enumeration value="Create">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Skapa konto.</documentation>
                </annotation>
            </enumeration>
            <enumeration value="Delete">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Avregistrera konto.</documentation>
                </annotation>
            </enumeration>
        </restriction>
    </simpleType>

    <element name="accountRequest">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Dokument som motsvarar en registrering eller en avregistrering av konto
                i FAR.
            </documentation>
        </annotation>
        <complexType>
            <sequence>
                <element ref="commonv4:recipientId">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Mottagaridentitet</documentation>
                    </annotation>
                </element>
                <element name="requestType" type="tns:requestType">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Typ av dokument.</documentation>
                    </annotation>
                </element>
                <element name="agreementText" type="string">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Text gällande villkor.</documentation>
                    </annotation>
                </element>
                <element ref="commonv4:timestamp">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Starttidpunkt för registreringen.</documentation>
                    </annotation>
                </element>
                <element name="serviceSupplier" type="string">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Namn på leverantören av brevlåda som mottagaren har valt.
                            Brevlådan måste vara registrerad i FAR.
                        </documentation>
                    </annotation>
                </element>
            </sequence>
        </complexType>
    </element>

    <element name="accountPreferences">
        <annotation>
            <documentation xml:lang="en">A list of senders, with an accompanying flag that states
                the recipients wish to either block or accept said sender.
                Note! This element can be used both for reading and writing data, which means that the number of
                senders in the list can mean different things, i.e. when reading, a total list is returned.
                When writing, a list of senders which value is changed is used.
            </documentation>
            <documentation xml:lang="sv">En mottagares inställningar för godkända avsändare. Representeras
                som en lista av avsändare, med tillhörande statusflagga som indikerar om mottagaren
                önskar blocka eller acceptera sagd avsändare.
                OBS! Detta element används både för läsning och skrivning av data, vilket innebär att antalet
                avsändare i listan kan betyda olika saker, i.e. vid läsning, så returneras en total lista från FaR.
                Vid skrivande operationer, så skall detta element innehålla de förändringar man önskar åstadkomma.
            </documentation>
        </annotation>
        <complexType>
            <sequence>
                <element ref="commonv4:recipientId">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Mottagarens (brevlådeinnehavarens) identitet.</documentation>
                    </annotation>
                </element>
                <element name="acceptedSenders" maxOccurs="unbounded">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Lista med avsändare och tillhörande flagga.</documentation>
                    </annotation>
                    <complexType>
                        <sequence>
                            <element ref="commonv4:swedishOrganizationId">
                                <annotation>
                                    <documentation xml:lang="en"></documentation>
                                    <documentation xml:lang="sv">Avsändarens identitet.</documentation>
                                </annotation>
                            </element>
                            <element name="isAccepted" type="boolean">
                                <annotation>
                                    <documentation xml:lang="en"></documentation>
                                    <documentation xml:lang="sv">Flagga som anger accepterad (sant), blockad (falskt).
                                    </documentation>
                                </annotation>
                            </element>
                        </sequence>
                    </complexType>
                </element>
            </sequence>
        </complexType>
    </element>

    <element name="pendingAccountRequest">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Dokument som motsvarar en påbörjad registrering eller avregistrering
                av konto i FAR.
            </documentation>
        </annotation>
        <complexType>
            <sequence>
                <element ref="tns:accountRequest">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Kontoinformation.</documentation>
                    </annotation>
                </element>
                <!-- Element renamed from SignatureStatus, if this is a problem, introduce a type and name the element accordingly -->
                <element ref="authorityv4:signatureAuthorizationResult">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Aktuell signaturkontroll status.</documentation>
                    </annotation>
                </element>
            </sequence>
        </complexType>
    </element>

    <element name="pendingAccountPreferences">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Pågående förändringar för ett konto, ännu inte fullständigt signerad.
            </documentation>
        </annotation>
        <complexType>
            <sequence>
                <element ref="tns:accountPreferences">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Nya inställningar för kontot.</documentation>
                    </annotation>
                </element>
                <element ref="authorityv4:signatureAuthorizationResult">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Resultat av underskriftstest.</documentation>
                    </annotation>
                </element>
            </sequence>
        </complexType>
    </element>

    <element name="pendingChangeServiceSupplier">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Information om ett påbörjat byte av brevlådeoperatör.</documentation>
        </annotation>
        <complexType>
            <sequence>
                <element ref="commonv4:serviceSupplierId" minOccurs="0">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Brevlådeoperatör bytet skall ske till.</documentation>
                    </annotation>
                </element>
                <element ref="authorityv4:signatureAuthorizationResult">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Aktuell signaturkontroll status.</documentation>
                    </annotation>
                </element>
            </sequence>
        </complexType>
    </element>

    <element name="accountInformation">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Information för ett konto, gällande auktorisation. Status, vilka som har
                signerat och vilka som kan signera ingår.
            </documentation>
        </annotation>
        <complexType>
            <sequence>
                <element name="accountStatus"
                         type="tns:accountActivityType"><!-- TODO Should be renamed for clarity? -->
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Statusinformation för ett konto.</documentation>
                    </annotation>
                </element>
                <element name="signedBy" type="commonv4:signerType" minOccurs="0" maxOccurs="unbounded">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">De signatärer som har signerat avtal.</documentation>
                    </annotation>
                </element>
                <element name="authoritzationStatus" type="authorityv4:authorizationStatusType">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Anger om avtalet är komplett signerat, dvs om de
                            signaturer som hittills inkommit i kombination med signatur från den
                            omfrågade gör att firmateckningsreglerna uppfylls (detta innebär dock inte
                            att kontot redan är aktivt).
                        </documentation>
                    </annotation>
                </element>
                <element name="serviceSupplier" type="string">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Brevlådeoperatör för kontot.</documentation>
                    </annotation>
                </element>
                <element name="agreementText" type="string" minOccurs="0">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Avtalstext.</documentation>
                    </annotation>
                </element>
            </sequence>
        </complexType>
    </element>

    <simpleType name="accountActivityType">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Statusinformation för ett konto. Anger om kontot är aktivt, eller
                det är under pågående registrering.
            </documentation>
        </annotation>
        <restriction base="string">
            <enumeration value="Active">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Kontot är aktivt.</documentation>
                </annotation>
            </enumeration>
            <enumeration value="Pending">
                <annotation>
                    <documentation xml:lang="en"></documentation>
                    <documentation xml:lang="sv">Kontot är under pågående registrering.</documentation>
                </annotation>
            </enumeration>
        </restriction>
    </simpleType>

    <element name="authorizedAccount">
        <annotation>
            <documentation xml:lang="en"></documentation>
            <documentation xml:lang="sv">Beskriver om en person är giltig signatär och information kring detta.
            </documentation>
        </annotation>
        <complexType>
            <sequence>
                <element name="isAccountAuthorizedSigner" type="boolean">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Om kontot är en giltig signatär.</documentation>
                    </annotation>
                </element>
                <element ref="commonv4:userId">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Identitet för en autenticerad användare. Behöver inte
                            nödvändigtvis representera användare med egen brevlåda (kan vara användare
                            som inte är mottagare).
                        </documentation>
                    </annotation>
                </element>
                <element ref="commonv4:organizationId">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Unik identitet för ett företag (organisationsnummer).
                        </documentation>
                    </annotation>
                </element>
                <element name="companyName" type="string">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Firmans namn, från Bolagsverket.</documentation>
                    </annotation>
                </element>
                <element name="companySignatureRuleText" type="string">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Beskrivning av firmateckningsregler för den omfrågade
                            firman, från Bolagsverket.
                        </documentation>
                    </annotation>
                </element>
                <element name="possibleSigners" type="commonv4:signerType" minOccurs="0" maxOccurs="unbounded">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Möjliga signatärer enligt firmateckningsregler från
                            Bolagsverket. För att en person skall ses ha behörighet, behöver denna vara
                            en av dessa PossibleSigners.
                        </documentation>
                    </annotation>
                </element>
                <element ref="tns:accountInformation" minOccurs="0">
                    <annotation>
                        <documentation xml:lang="en"></documentation>
                        <documentation xml:lang="sv">Information för ett konto, detta returneras alltid utom i de
                            fall att det inte finns ett konto upplagt, dvs inte ens påbörjat.
                        </documentation>
                    </annotation>
                </element>
            </sequence>
        </complexType>
    </element>
</schema>
