<?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:emcstypes="http://www.mf.gov.pl/schematy/EMCSPL3/EMCSTYPES/2019/10/"
           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:dd815b="http://www.mf.gov.pl/schematy/EDD/DD815B/2020/05/"
           targetNamespace="http://www.mf.gov.pl/schematy/EDD/DD815B/2020/05/">
  <!--=========================================-->
  <!--=====              DD815B           =====-->
  <!--=====          Projekt e-DDB        =====-->
  <!--=========================================-->

  <!--===== 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/EMCSPL3/EMCSTYPES/2019/10/" schemaLocation="emcsTypes.xsd" />
  <xs:import namespace="http://www.mf.gov.pl/schematy/EDD/DDTYPES/2020/05/" schemaLocation="ddTypes.xsd"/>

  <!--===== Root Element =====-->
  <xs:element name="DD815B" type="dd815b:DD815BType"/>

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

  <!--===== DD Specific Data Groups Declarations =====-->
  <xs:complexType name="BodyType">
    <xs:sequence>
      <xs:element name="SubmittedDraftOfEDD" type="dd815b:SubmittedDraftOfEDDType"/>
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--===              SubmittedDraftOfEDDType               ===-->
  <!--==========================================================-->
  <xs:complexType name="SubmittedDraftOfEDDType">
    <xs:sequence>
      <xs:element name="DDDraft" type="dd815b:DDDraftType"/>

      <!-- sekcja 2 i 4 -->
      <xs:element name="ConsignorTrader"   type="ddtypes:DDTraderType" minOccurs="1" maxOccurs="1" />
      <xs:element name="PlaceOfDispatchTrader" type="ddtypes:DDTraderType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="PlaceOfDispatchCustomsOffice" type="ddtypes:DDCustomsOfficeType" minOccurs="1" maxOccurs="1"/>

      <!-- sekcja 5 -->
      <xs:element name="ConsigneeTraders" type="ddtypes:DDConsigneeTradersType" minOccurs="0" maxOccurs="unbounded"/>

      <!-- sekcja 6 i 8 -->
      <xs:element name="DDMovementGuarantee" type="dd815b:DDGuaranteeType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="DDStorageGuarantee" type="dd815b:DDStorageGuaranteeType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="DDStorageGuaranteeAmount" type="dd815b:DDStorageGuaranteeAmountType" minOccurs="0" maxOccurs="999"/>

      <!-- sekcja 9 -->
      <xs:element name="TransportMode" type="ddtypes:DDTransportModeType"/>

      <!-- sekcja 10 -->
      <xs:element name="TransportDetails" type="ddtypes:DDTransportDetailsType" />

      <!-- sekcja 11 -->
      <xs:element name="BodyEDD" type="ddtypes:BodyEDDType" />

      <!-- Dokumenty dodatkowe -->
      <xs:element name="AdditionalDocument" type="ddtypes:DDAdditionalDocType" minOccurs="0" maxOccurs="99"/>

    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--===                    DDDraftType                     ===-->
  <!--==========================================================-->
  <xs:complexType name="DDDraftType">
    <xs:sequence>
      <!-- 1a -->
      <xs:element name="LocalReferenceNumber" type="ddtypes:DeliveryDocumentLocalReferenceNumberType"/>

      <!-- 1b -->
      <xs:element name="DeliveryDocumentMode" type="ddtypes:DeliveryDocumentModeFlag" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>Znacznik zwrotu towarów: 1 - zwrot; 0 albo brak elementu - dostawa</xs:documentation>
        </xs:annotation>
      </xs:element>

      <!-- 1c -->
      <xs:element name="ExciseDutyRate" minOccurs="1" maxOccurs="1" type="ddtypes:ExciseDutyRateType">
        <xs:annotation>
          <xs:documentation>
            Atrybut może być określony tylko w DD815 i nie może być znieniony do czasu zakończenia całej dostawy ze względu na założenie,
            że komunikat modyfikacji dostawy nie może zmienić pozycji towarowych (ilości ani typu).
          </xs:documentation>
        </xs:annotation>
      </xs:element>

      <!-- 1d -->
      <xs:element name="DeferredSubmissionFlag" type="tcl:Flag" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>Znacznik zgłoszenia w trybie odroczonym: 1 - tryb odroczony; 0 albo brak elementu - tryb standardowy</xs:documentation>
        </xs:annotation>
      </xs:element>

      <!-- 1e 1f -->
      <xs:element name="InvoiceNumber" type="emcs:InvoiceNumberType"/>
      <xs:element name="InvoiceDate" type="emcs:DateType"/>

      <!-- 1g 1h -->
      <xs:element name="DateOfDispatch" type="emcs:DateType"/>
      <xs:element name="TimeOfDispatch" type="emcs:TimeType"/>

      <!-- 1i -->
      <xs:element name="JourneyTime" type="emcs:JourneyTimeType"/>

      <!-- 1j -->
      <xs:element name="DeliveryClosingFlag" minOccurs="1" maxOccurs="1" type="ddtypes:DeliveryClosingFlagType">
        <xs:annotation>
          <xs:documentation>
            Atrybut określa tryb zamknięcia dostawy. Może być zmieniony w wyniku modyfikacji dostawy (np zmiany odbiorcy) pod warunkiem, że był ustawiony
            pierwotnie na 1 albo 2. Zmiana może być dokonana tylko na wartość 1 albo 2.
            Jeśli pierwotnie ustawiony był na 3 to nie może być zmieniany.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--===                  DDGuaranteeType                   ===-->
  <!--==========================================================-->
  <xs:complexType name="DDGuaranteeType">
    <xs:annotation>
      <xs:documentation>
        <doc:description xml:lang="pl" value="11 Gwarancja dotycząca dostawy"/>
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="GuarantorTypeCode" type="tcl:GuarantorTypeCode"/>
      <xs:element name="GuarantorTrader" type="ddtypes:GuarantorTraderType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="GuaranteeReferenceNumber" type="emcstypes:GuaranteeReferenceNumberType"/>
      <xs:element name="GuaranteeReferenceNumberAccessCode" type="emcstypes:GuaranteeReferenceNumberAccessCodeType"/>
      <xs:element name="ConsignorTIN" type="emcstypes:TINType"/>
      <xs:element name="GuarantorTIN" type="emcstypes:TINType"/>
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--===               DDStorageGuaranteeType               ===-->
  <!--==========================================================-->
  <xs:complexType name="DDStorageGuaranteeType">
    <xs:annotation>
      <xs:documentation>
        <doc:description xml:lang="pl" value="11 Gwarancja dotycząca dostawy"/>
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="GuaranteeReferenceNumber" type="emcstypes:GuaranteeReferenceNumberType"/>
      <xs:element name="GuaranteeReferenceNumberAccessCode" type="emcstypes:GuaranteeReferenceNumberAccessCodeType"/>
      <xs:element name="ConsignorTIN" type="emcstypes:TINType"/>
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--===            DDStorageGuaranteeAmountType            ===-->
  <!--==========================================================-->
  <xs:complexType name="DDStorageGuaranteeAmountType">
    <xs:annotation>
      <xs:documentation>
        <doc:description xml:lang="pl" value="Identyfikator zabezpieczenia z dokumentu e-AD"/>
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="AdministrativeReferenceCode" type="emcs:AdministrativeReferenceCodeType" minOccurs="1" maxOccurs="1"/>
      <xs:element name="GuaranteeAmount" type="ddtypes:GuaranteeAmountType" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>