<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.00"
           xmlns:emcs="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:EMCS:V2.02"
           xmlns:ddtypes="http://www.mf.gov.pl/schematy/EDD/DDTYPES/2020/05/"
           xmlns:tms="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TMS:V2.02"
           xmlns:tcl="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TCL:V2.02"
           xmlns:doc="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:DOC:V2.02"
           xmlns:dd704="http://www.mf.gov.pl/schematy/EDD/DD704/2020/05/"
           targetNamespace="http://www.mf.gov.pl/schematy/EDD/DD704/2020/05/">
  <!--=====================================================-->
  <!--=====                   DD704                   =====-->
  <!--===== Komunikat informujący o błędach walidacji =====-->
  <!--=====================================================-->

  <!--===== Imports =====-->
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:EMCS:V2.02" schemaLocation="types.xsd"/>
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TMS:V2.02" schemaLocation="tms.xsd"/>
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TCL:V2.02" schemaLocation="tcl.xsd"/>
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:DOC:V2.02" schemaLocation="doc.xsd"/>
  <xs:import namespace="http://www.mf.gov.pl/schematy/EDD/DDTYPES/2020/05/" schemaLocation="ddTypes.xsd"/>

  <!--===== Root Element =====-->
  <xs:element name="DD704" type="dd704:DD704Type"/>

  <!--===== EMCS Data Groups Declarations =====-->
  <xs:complexType name="DD704Type">
    <xs:sequence>
      <xs:element name="Header" type="tms:HeaderType"/>
      <xs:element name="Body" type="dd704:BodyType"/>
    </xs:sequence>
  </xs:complexType>

  <!--===== IE Specific Data Groups Declarations =====-->
  <xs:complexType name="BodyType">
    <xs:sequence>
      <xs:element name="GenericRefusalMessage" type="dd704:GenericRefusalMessageType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="GenericRefusalMessageType">
    <xs:sequence>
      <!-- Referencja na dokument staje się obowiązkowa. Ewentualnie do zmiany jeśli znajdziemy przypadek, 
           w którym nie da się wskazać dokumentu 
           Do przemyślenia jest jeszcze kwestia umieszczenia w tym miejscu rozróżnienia co do wyboru
           rodzaju referencji na dokument (lokalna vs. administracyjna) -->
      <xs:element name="DeliveryDocumentReference" type="ddtypes:DeliveryDocumentReferenceType" minOccurs="1" maxOccurs="1"/>

      <!-- Żeby była potrzeba wysyłania 704 musi być jakiś błąd -->
      <xs:element name="Error" type="dd704:ErrorType" minOccurs="1" maxOccurs="999"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="ErrorType">
    <xs:sequence>
      <xs:element name="ErrorType"              type="dd704:ErrorCodes"                 minOccurs="1" maxOccurs="1"/>
      <xs:element name="ErrorReason"            type="dd704:ErrorReasonType"            minOccurs="1" maxOccurs="1"/>
      <xs:element name="ErrorLocation"          type="dd704:ErrorLocationType"          minOccurs="0" maxOccurs="1"/>
      <xs:element name="OriginalAttributeValue" type="dd704:OriginalAttributeValueType" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <!--===== IE Specific Data Items Declarations =====-->

  <!--==========================================================-->
  <!--=====                  Error Codes                   =====-->
  <!--==========================================================-->
  <xs:simpleType name="ErrorCodes">
    <xs:union memberTypes="tcl:FunctionalErrorCodes dd704:NonFunctionalErrorCodes"/>
  </xs:simpleType>

  <!--==========================================================-->
  <!--=====           Non Functional Error Codes           =====-->
  <!--==========================================================-->
  <xs:simpleType name="NonFunctionalErrorCodes">
    <xs:annotation>
      <xs:documentation>Kody błędów niefunkcjonalnych</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:nonNegativeInteger">
      <xs:enumeration value="1">
        <xs:annotation>
          <xs:documentation>Błąd zajęcia zabezpieczenia</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="2">
        <xs:annotation>
          <xs:documentation>Negatywny wynik kontroli</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="3">
        <xs:annotation>
          <xs:documentation>Zbyt duże różnice w ilości wyrobów</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="4">
        <xs:annotation>
          <xs:documentation>Nieprawidłowy LRN</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <!--<xs:enumeration value="5">
        <xs:annotation>
          <xs:documentation>Projekcie e-DD jest niezgodny z powiadomieniem</xs:documentation>
        </xs:annotation>
      </xs:enumeration>-->
      <xs:enumeration value="6">
        <xs:annotation>
          <xs:documentation>Nadawca komunikatu nie jest uprawniony do jego wysyłki</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="7">
        <xs:annotation>
          <xs:documentation>Brak elementu/wartości</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="8">
        <xs:annotation>
          <xs:documentation>Nieznany LRN</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="9">
        <xs:annotation>
          <xs:documentation>Brak interfejsu komunikacyjnego dla Odbierającego</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="10">
        <xs:annotation>
          <xs:documentation>Timer został wygaszony</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="11">
        <xs:annotation>
          <xs:documentation>Zarejestrowano zmianę odbiorcy</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="13">
        <xs:annotation>
          <xs:documentation>Niezarejestrowano raportu</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <!--==========================================================-->
  <!--=====                  Error Reason                  =====-->
  <!--==========================================================-->
  <xs:simpleType name="ErrorReasonType">
    <xs:annotation>
      <xs:documentation>
        <doc:description value="Error Reason"/>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:token">
      <xs:maxLength value="350"/>
      <xs:pattern value=".{1,350}"/>
    </xs:restriction>
  </xs:simpleType>

  <!--==========================================================-->
  <!--=====                 Error Location                 =====-->
  <!--==========================================================-->
  <xs:simpleType name="ErrorLocationType">
    <xs:annotation>
      <xs:documentation>
        <doc:description value="Error Location"/>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:token">
      <xs:maxLength value="350"/>
      <xs:pattern value=".{1,350}"/>
    </xs:restriction>
  </xs:simpleType>

  <!--==========================================================-->
  <!--=====            Original Attribute Value            =====-->
  <!--==========================================================-->
  <xs:simpleType name="OriginalAttributeValueType">
    <xs:annotation>
      <xs:documentation>
        <doc:description value="Original Attribute Value"/>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:token">
      <xs:maxLength value="350"/>
      <xs:pattern value=".{1,350}"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>