<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="movementIngest" nillable="true" type="MovementIngest" />
  <xs:complexType name="MovementIngest">
    <xs:annotation>
      <xs:documentation>The root of the request</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="version" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Version of the service contract, in this case ‘1.0’</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="movements" type="ArrayOfMovement">
        <xs:annotation>
          <xs:documentation>The header level data of the movement</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="ArrayOfMovement">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="movement" nillable="true" type="Movement" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="Movement">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="timestamp" nillable="true" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="documentReference" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Reference to the document that triggered the creation of movement (SAP: ZMBLNR)</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="externalReference" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique external reference movement</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="externalMovementType" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Type of movement as known by inventory or warehouse management system</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="customsMovementType" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Deprecated, replaced by Movement Type</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="movementLines" type="ArrayOfMovementLine">
        <xs:annotation>
          <xs:documentation>The item level data of the movement</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="movementType" nillable="true" type="MovementType">
        <xs:annotation>
          <xs:documentation>CAS movement type</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="category" nillable="true" type="MovementCategory">
        <xs:annotation>
          <xs:documentation>The category defines in which column on the excise register the quantity will be shown
             Mandatory for ADJP and ADJN if the movement is also applicable for a tax warehouse</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="remark" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>If used for a tax warehouse stock correction, it will be shown in column '7. Remarks' of the excise register</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="movementAdjustmentData" nillable="true" type="MovementAdjustmentData">
        <xs:annotation>
          <xs:documentation>Data that can be provided in case of a positive or negative stock adjustments related to a tax warehouse</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="customsDestination" nillable="true" type="CustomsDestination">
        <xs:annotation>
          <xs:documentation>The customs destination of the movement. Only applicable for RFFC and ADJN movement types.
             HomeUse: simultaneous release for free circulation and home use of goods (procedure 40 in the H1 declaration).
             PartialHomeUse: release of goods for free circulation and partial entry for home use (procedure 45 in the H1 declaration).</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="writeOffRules" nillable="true" type="ArrayOfMovementWriteOffRule">
        <xs:annotation>
          <xs:documentation>A set of write-off rules: what kind of stock needs to be released into free circulation for an RFFC or ADJN movement order.
             Stock will be released until the quantities are satisfied, in the order provided.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="ArrayOfMovementLine">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="movementLine" nillable="true" type="MovementLine" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="MovementLine">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="itemId" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique identifier of the item/material as defined in master data</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="itemDescription" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>An optional description for the item. Will be displayed in stock and movement views.
            If not provided, CAS will deduct it from Master Data.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="direction" type="Direction">
        <xs:annotation>
          <xs:documentation>Direction of the movement</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="serialBatchReference" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique serial or batch number of the item</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="quantity" nillable="true" type="xs:decimal">
        <xs:annotation>
          <xs:documentation>Quantity of the item in the base unit of measure as defined in master data</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="uom" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unit of measure in which the quantity is defined.
            
            Main used codes:
            - DTN: Hectokilogram
            - HLT: Hectolitre
            - KGM: Kilogram
            - LPA: Litre pure (100%) alcohol
            - LTR: Litre
            - L15: Litres at 15 °C
            - L20: Litres at 20 °C
            - MTK: Square metre
            - NAR: Piece
            - 101: Hectolitres pure alcohol at 20 °C
            - 102: 1.000 litres at 15 °C
            - KGV: KGM Vacuum</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="storageLocationReference" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Storage location reference (as known in CAS)</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="receivingStorageLocationReference" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>For transfer movements (TRFA, TRFR)
            Mandatory for TRFR</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="receivingAuthorizationId" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>For transfer movement between authorizations (TRFA)
            Mandatory for TRFA</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="stockRecordId" nillable="true" type="xs:long">
        <xs:annotation>
          <xs:documentation>Stock record id, only used for movements initiated by CAS UI</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="authorizationId" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>For transfer movements (TRFA, TRFR)
            Mandatory for movement type TRFA, and when there are multiple special procedure and/or tax warehouse authorisations on the storage location</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="exciseProductCode" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Excise Product code.
            If not provided CAS will try to deduct it from Item Master Data.
            
            Some example codes:
            - B000: Beer
            - E300: Mineral oils
            - S300: Ethyl alcohol
            - W300: Sparkling wine
            
            For movements of excise products in Belgium the excise product code is needed to correctly construct the excise register.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="density" nillable="true" type="xs:decimal">
        <xs:annotation>
          <xs:documentation>The Density as ingested or indicated by a user,
            Which can then be used to calculate an additional quantity and to be taken over in subsequent outbound EMCS movements
            Only used for IN lines: result of a production or positive stock adjustment</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="asv" nillable="true" type="xs:decimal">
        <xs:annotation>
          <xs:documentation>Alcohol % by volume, sometimes also abbreviated as ABV
            Applicable in case of production of an alcoholic product.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="preferentialOriginCountry" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>The preferential origin country of a good being produced.
            May be provided in the IN movement line for PROC, UFOH and ADJP movement types</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="nonPreferentialOriginCountry" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>The non-preferential origin country of a good being produced.
            May be provided in the IN movement line for PROC, UFOH and ADJP movement types</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="quantities" nillable="true" type="ArrayOfMovementLineQuantity">
        <xs:annotation>
          <xs:documentation>Quantities</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="blendResult" nillable="true" type="MovementLineBlendResult">
        <xs:annotation>
          <xs:documentation>Used to indicated the result of a TRFB (Transfer + Blend) movement</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="Direction">
    <xs:restriction base="xs:string">
      <xs:enumeration value="UNKNOWN" />
      <xs:enumeration value="IN" />
      <xs:enumeration value="OUT" />
      <xs:enumeration value="TRANSFER" />
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="ArrayOfMovementLineQuantity">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="quantity" nillable="true" type="MovementLineQuantity" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="MovementLineQuantity">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="quantity" type="xs:decimal">
        <xs:annotation>
          <xs:documentation>Quantity of the item in a given UoM</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="1" maxOccurs="1" name="uom" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unit of measure in which the quantity is defined</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="MovementLineBlendResult">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="itemId" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique identifier of the item/material as defined in master data that will be the result of a TRFB (Transfer + Blend) movement</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="exciseProductCode" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Excise Product code.
            If not provided CAS will try to deduct it from Resulting Item Master Data.
            
            Some example codes:
            B000: Beer
            E300: Mineral oils
            S300: Ethyl alcohol
            W300: Sparkling wine
            …
            
            For TRFB movements of excise products in Belgium the resulting excise product code is needed to correctly construct the excise register.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="serialBatchReference" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique serial or batch number of the result of a TRFB (Transfer + Blend) movement</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="MovementType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="UNKNOWN" />
      <xs:enumeration value="PROC" />
      <xs:enumeration value="UFOH" />
      <xs:enumeration value="ADJP" />
      <xs:enumeration value="ADJN" />
      <xs:enumeration value="TRFA" />
      <xs:enumeration value="TRFR" />
      <xs:enumeration value="TRFB" />
      <xs:enumeration value="INVD" />
      <xs:enumeration value="DCSV" />
      <xs:enumeration value="RFFC" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="MovementCategory">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Unknown" />
      <xs:enumeration value="DispatchUnderSuspension" />
      <xs:enumeration value="Export" />
      <xs:enumeration value="ReceivedUnderSuspension" />
      <xs:enumeration value="Production" />
      <xs:enumeration value="FictiveArrival" />
      <xs:enumeration value="ArrivalCorrection" />
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="MovementAdjustmentData">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="arc" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>Administrative reference code of an e-AD, for a positive or negative correction movement related to an e-AD</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="arcSequenceNumber" nillable="true" type="xs:int">
        <xs:annotation>
          <xs:documentation>Sequence number of an e-AD, for a positive or negative correction movement related to an e-AD</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="mrn" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>MRN of a related export, for a positive or negative correction movement related to an e-AD for export</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="CustomsDestination">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Unknown" />
      <xs:enumeration value="HomeUse" />
      <xs:enumeration value="PartialHomeUse" />
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="ArrayOfMovementWriteOffRule">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="writeOffRule" nillable="true" type="MovementWriteOffRule" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="MovementWriteOffRule">
    <xs:annotation>
      <xs:documentation>A write-off rule: what kind of stock needs to be released into free circulation for an RFFC or ADJN movement order.
            Stock will be released until the quantities are satisfied, in the order provided.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="customsStatus" nillable="true" type="WriteOffCustomsStatus">
        <xs:annotation>
          <xs:documentation>One of:
            - Free
            - Bonded</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="isOfPreferentialOrigin" nillable="true" type="xs:boolean">
        <xs:annotation>
          <xs:documentation>Whether to select stock of preferential origin.
            true: select stock that is of preferential origin (regardless of country of preferential origin)
            false: select stock that is not of preferential origin
            When omitted, the rule does not constrain selection by preferential origin.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="preferentialOriginCountry" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>The country of preferential origin to pick stock for</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="nonPreferentialOriginCountry" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>The country of non-preferential origin to pick stock for</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="inboundDocRefNum" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>The MRN of the inbound declaration from which stock is written off</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="inboundFunctionRefNum" nillable="true" type="xs:string">
        <xs:annotation>
          <xs:documentation>The LRN of the inbound declaration from which stock is written off
            (It is advised to only use InboundFunctionRefNum if the inbound declaration was an EIDR, and thus doesn't have an MRN)</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="WriteOffCustomsStatus">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Unknown" />
      <xs:enumeration value="Free" />
      <xs:enumeration value="Bonded" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>