<?xml version="1.0" encoding="utf-8"?>
<!--
  NRA HFRG - schema for the Flat XML Import Format.

  Covers all three root elements of the format:
    HFRGBULGARIA - transport declarations: Import (9), Export (10), Internal (13), ThirdCountry (14)
    HFRGAnnul    - cancellation (11)
    HFRGConfirm  - confirmation (12)

  The format has no target namespace. Reference it from an instance document with:
    <HFRGBULGARIA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:noNamespaceSchemaLocation="flat-import.xsd">

  ============================================================================
  Relation to the official NRA schemas (decHfr_*_v5_restrict.xsd)
  ============================================================================

  Every length, pattern and enumeration below is copied from the NRA schema for
  the element it converts into, so a file that passes this schema will not be
  rejected later for a value-level reason. Nothing here is stricter than the NRA
  rule it mirrors.

  Where the NRA schemas disagree with each other, the flat type is the union:

    * Carrier / Organizer / TransCarrier identifier
        NRA: reprperson/egn is [0-9]{10} exactly; reprfirm/bulstat is the "vin"
        type [A-Z0-9+*]{1,15}. Which one applies depends on the ...IsPerson flag,
        and XSD 1.0 cannot switch on another element, so the wider of the two
        (vin) is used. It is a strict superset of egn.
    * Carrier / Organizer / TransCarrier identifier type
        NRA: egntype (2,3,5,6) for a person, vintype (1,5,6,9) for a firm.
        The union 1,2,3,5,6,9 is used here for the same reason.
    * Purpose
        NRA: 01-07 for Import and Export, 01,02,03,04,06 for Internal,
        01,06,07 for ThirdCountry. 01-07 is accepted here; the per-type subset
        is listed in field-mapping.md.

  Deliberately different, because these elements have no NRA counterpart:

    * Version, FiscalRegNo, TransportDate, InternalReference, TaxpayerIdent,
      TaxpayerIdentType - flat-format-only header metadata.
    * The *Ekatte elements carry a 4-digit POSTAL CODE, which the hub resolves to
      an EKATTE code through wwwroot/data/postal-to-ekatte.json. The NRA ekatte
      type ([0-9]{1,5}) applies to the converted value, not to what you write here.
    * QuantityType additionally accepts kg / m2 / pcs, which the hub maps onto the
      NRA values кг / м2 / броя.

  ============================================================================
  What this schema does not check
  ============================================================================

  1. Which elements are REQUIRED. That depends on OperationType, and XSD 1.0 has
     no conditional validation, so nearly everything is minOccurs="0".
     field-mapping.md is the reference for per-declaration-type requirements.

  2. Element order. The converter looks elements up by name, so the schema uses
     xs:all and accepts any order.

  3. Empty elements are valid everywhere: the converter treats an empty element as
     absent. Typed values are therefore modelled as a union with the empty string.

  4. Time values. The NRA schemas only constrain these to 5 characters and document
     the hh:mm shape, so that is all that is enforced here. The hub normalizes
     anything it cannot parse to 00:00.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

  <!-- ============================================================
       Building blocks
       ============================================================ -->

  <xs:simpleType name="Empty">
    <xs:restriction base="xs:string">
      <xs:length value="0"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: numb (maxLength 5) -->
  <xs:simpleType name="Text5">
    <xs:restriction base="xs:string">
      <xs:maxLength value="5"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: customsoffice, customslocation (maxLength 8) -->
  <xs:simpleType name="Text8">
    <xs:restriction base="xs:string">
      <xs:maxLength value="8"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: cphone (maxLength 10) -->
  <xs:simpleType name="Text10">
    <xs:restriction base="xs:string">
      <xs:maxLength value="10"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: uin, uinreceived, uinsent (maxLength 13) -->
  <xs:simpleType name="Text13">
    <xs:restriction base="xs:string">
      <xs:maxLength value="13"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: code, customs/document (maxLength 20) -->
  <xs:simpleType name="Text20">
    <xs:restriction base="xs:string">
      <xs:maxLength value="20"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: localaddress, street (maxLength 100) -->
  <xs:simpleType name="Text100">
    <xs:restriction base="xs:string">
      <xs:maxLength value="100"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: crname, tname, reprperson/name, reprfirm/name, cname, dname (maxLength 200) -->
  <xs:simpleType name="Text200">
    <xs:restriction base="xs:string">
      <xs:maxLength value="200"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: purposeother (maxLength 1000) -->
  <xs:simpleType name="Text1000">
    <xs:restriction base="xs:string">
      <xs:maxLength value="1000"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- The NRA schemas use xs:boolean. The converter is more forgiving: "true" in any
       case or "1" is true, anything else is false. -->
  <xs:simpleType name="BooleanValue">
    <xs:restriction base="xs:string">
      <xs:pattern value="[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[01]"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Boolean">
    <xs:union memberTypes="BooleanValue Empty"/>
  </xs:simpleType>

  <!-- NRA: receiveddate, loaddate, transdate, transferdate, customsdate (xs:date) -->
  <xs:simpleType name="Date">
    <xs:union memberTypes="xs:date Empty"/>
  </xs:simpleType>

  <!-- Flat-only header metadata; no NRA counterpart. -->
  <xs:simpleType name="DateTime">
    <xs:union memberTypes="xs:dateTime xs:date Empty"/>
  </xs:simpleType>

  <!-- NRA: receivedtime, loadtime, transtime, transfertime, customstime are
       xs:string with maxLength 5, documented as hh:mm. Same rule here. -->
  <xs:simpleType name="Time">
    <xs:restriction base="xs:string">
      <xs:maxLength value="5"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: price (xs:decimal, fractionDigits 2) -->
  <xs:simpleType name="Decimal2Value">
    <xs:restriction base="xs:decimal">
      <xs:fractionDigits value="2"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Decimal2">
    <xs:union memberTypes="Decimal2Value Empty"/>
  </xs:simpleType>

  <!-- NRA: quantitynet, quantitygross (xs:decimal, fractionDigits 3) -->
  <xs:simpleType name="Decimal3Value">
    <xs:restriction base="xs:decimal">
      <xs:fractionDigits value="3"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Decimal3">
    <xs:union memberTypes="Decimal3Value Empty"/>
  </xs:simpleType>

  <!-- Flat-only: 4-digit postal code, resolved to an EKATTE code by the hub. -->
  <xs:simpleType name="PostalCodeValue">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{4}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="PostalCode">
    <xs:union memberTypes="PostalCodeValue Empty"/>
  </xs:simpleType>

  <!-- NRA: recipient/ident, shipper/ident and annul part1/ident - restriction of
       "bulstat" with minLength 9. -->
  <xs:simpleType name="SubjectIdentValue">
    <xs:restriction base="xs:string">
      <xs:minLength value="9"/>
      <xs:maxLength value="13"/>
      <xs:pattern value="[0-9]{1,13}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="SubjectIdent">
    <xs:union memberTypes="SubjectIdentValue Empty"/>
  </xs:simpleType>

  <!-- NRA: confirm part1/ident - "bulstat" without the minLength 9 the other
       declarations impose. -->
  <xs:simpleType name="BulstatValue">
    <xs:restriction base="xs:string">
      <xs:maxLength value="13"/>
      <xs:pattern value="[0-9]{1,13}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Bulstat">
    <xs:union memberTypes="BulstatValue Empty"/>
  </xs:simpleType>

  <!-- NRA: the "vin" type - crident, tident, reprfirm/bulstat. -->
  <xs:simpleType name="VinValue">
    <xs:restriction base="xs:string">
      <xs:maxLength value="15"/>
      <xs:pattern value="[A-Z0-9\+\*]{1,15}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Vin">
    <xs:union memberTypes="VinValue Empty"/>
  </xs:simpleType>

  <!-- NRA: regvehicle, regtrailer1, regtrailer2 -->
  <xs:simpleType name="RegPlateValue">
    <xs:restriction base="xs:string">
      <xs:maxLength value="15"/>
      <xs:pattern value="[0-9A-Z]{1,15}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="RegPlate">
    <xs:union memberTypes="RegPlateValue Empty"/>
  </xs:simpleType>

  <!-- NRA: the "identtype" type - 1=Bulstat, 2=PIN, 3=FPN, 5=NRA. -->
  <xs:simpleType name="MainIdentTypeValue">
    <xs:restriction base="xs:integer">
      <xs:enumeration value="1"/>
      <xs:enumeration value="2"/>
      <xs:enumeration value="3"/>
      <xs:enumeration value="5"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="MainIdentType">
    <xs:union memberTypes="MainIdentTypeValue Empty"/>
  </xs:simpleType>

  <!-- NRA: the "vintype" type - 1=Bulstat, 5=NRA, 6=Other, 9=VIN. -->
  <xs:simpleType name="FirmIdentTypeValue">
    <xs:restriction base="xs:integer">
      <xs:enumeration value="1"/>
      <xs:enumeration value="5"/>
      <xs:enumeration value="6"/>
      <xs:enumeration value="9"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="FirmIdentType">
    <xs:union memberTypes="FirmIdentTypeValue Empty"/>
  </xs:simpleType>

  <!-- NRA: "egntype" (2,3,5,6) for a person or "vintype" (1,5,6,9) for a firm. -->
  <xs:simpleType name="CarrierIdentTypeValue">
    <xs:restriction base="xs:integer">
      <xs:enumeration value="1"/>
      <xs:enumeration value="2"/>
      <xs:enumeration value="3"/>
      <xs:enumeration value="5"/>
      <xs:enumeration value="6"/>
      <xs:enumeration value="9"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="CarrierIdentType">
    <xs:union memberTypes="CarrierIdentTypeValue Empty"/>
  </xs:simpleType>

  <!-- NRA: transhipment/transporttype - xs:string enumeration 1=Water, 2=Railway, 3=Air. -->
  <xs:simpleType name="TransportType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="1"/>
      <xs:enumeration value="2"/>
      <xs:enumeration value="3"/>
      <xs:enumeration value=""/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: the "country" type - xs:string, maxLength 2. -->
  <xs:simpleType name="Country">
    <xs:restriction base="xs:string">
      <xs:maxLength value="2"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: purpose. The valid subset depends on the declaration type:
       Import 01-07, Export 01-07, Internal 01,02,03,04,06, ThirdCountry 01,06,07. -->
  <xs:simpleType name="Purpose">
    <xs:restriction base="xs:string">
      <xs:enumeration value="01"/>
      <xs:enumeration value="02"/>
      <xs:enumeration value="03"/>
      <xs:enumeration value="04"/>
      <xs:enumeration value="05"/>
      <xs:enumeration value="06"/>
      <xs:enumeration value="07"/>
      <xs:enumeration value=""/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: quantitytype - кг, м2, броя. The English forms are mapped by the hub. -->
  <xs:simpleType name="QuantityType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="kg"/>
      <xs:enumeration value="m2"/>
      <xs:enumeration value="pcs"/>
      <xs:enumeration value="кг"/>
      <xs:enumeration value="м2"/>
      <xs:enumeration value="броя"/>
      <xs:enumeration value=""/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: cphonecode -->
  <xs:simpleType name="PhoneCode">
    <xs:restriction base="xs:string">
      <xs:maxLength value="10"/>
      <xs:pattern value="(\+)?[0-9 \-]{0,10}"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- NRA: cpemail -->
  <xs:simpleType name="EmailValue">
    <xs:restriction base="xs:string">
      <xs:maxLength value="200"/>
      <xs:pattern value="[^@]+@[^\.]+\..+"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Email">
    <xs:union memberTypes="EmailValue Empty"/>
  </xs:simpleType>

  <!-- Flat-only: NRA IdentifierType name, or its number. -->
  <xs:simpleType name="TaxpayerIdentType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="IND_EGN"/>
      <xs:enumeration value="IND_LNCH"/>
      <xs:enumeration value="IND_SLNO"/>
      <xs:enumeration value="IND_BULSTAT"/>
      <xs:enumeration value="BUS_BULSTAT"/>
      <xs:enumeration value="1"/>
      <xs:enumeration value="2"/>
      <xs:enumeration value="3"/>
      <xs:enumeration value="4"/>
      <xs:enumeration value="5"/>
      <xs:enumeration value=""/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ============================================================
       Goods
       ============================================================ -->

  <xs:complexType name="GoodType">
    <xs:all>
      <xs:element name="Code" type="Text20" minOccurs="0"/>
      <xs:element name="QuantityType" type="QuantityType" minOccurs="0"/>
      <xs:element name="QuantityNet" type="Decimal3" minOccurs="0"/>
      <xs:element name="QuantityGross" type="Decimal3" minOccurs="0"/>
      <xs:element name="Price" type="Decimal2" minOccurs="0"/>
      <xs:element name="Purpose" type="Purpose" minOccurs="0"/>
      <xs:element name="PurposeOther" type="Text1000" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="GoodsType">
    <xs:sequence>
      <xs:element name="Good" type="GoodType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <!-- ============================================================
       Counterparties (Import, Internal, ThirdCountry)
       ============================================================ -->

  <xs:complexType name="CounterpartyAddressType">
    <xs:all>
      <xs:element name="LocalAddress" type="Text100" minOccurs="0"/>
      <xs:element name="Street" type="Text100" minOccurs="0"/>
      <xs:element name="Number" type="Text5" minOccurs="0"/>
      <xs:element name="Ekatte" type="PostalCode" minOccurs="0"/>
      <xs:element name="ReceivedDate" type="Date" minOccurs="0"/>
      <xs:element name="ReceivedTime" type="Time" minOccurs="0"/>
      <xs:element name="Goods" type="GoodsType" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="AddressesType">
    <xs:sequence>
      <xs:element name="Address" type="CounterpartyAddressType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="CounterpartyType">
    <xs:all>
      <xs:element name="Ident" type="Vin" minOccurs="0"/>
      <xs:element name="IdentType" type="FirmIdentType" minOccurs="0"/>
      <xs:element name="Name" type="Text200" minOccurs="0"/>
      <xs:element name="TIdent" type="Vin" minOccurs="0"/>
      <xs:element name="TIdentType" type="FirmIdentType" minOccurs="0"/>
      <xs:element name="TName" type="Text200" minOccurs="0"/>
      <xs:element name="Addresses" type="AddressesType" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="CounterpartiesType">
    <xs:sequence>
      <xs:element name="Counterparty" type="CounterpartyType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <!-- ============================================================
       Buyers (Export)
       ============================================================ -->

  <xs:complexType name="BuyerType">
    <xs:all>
      <xs:element name="Ident" type="Vin" minOccurs="0"/>
      <xs:element name="IdentType" type="FirmIdentType" minOccurs="0"/>
      <xs:element name="Name" type="Text200" minOccurs="0"/>
      <xs:element name="TIdent" type="Vin" minOccurs="0"/>
      <xs:element name="TIdentType" type="FirmIdentType" minOccurs="0"/>
      <xs:element name="TName" type="Text200" minOccurs="0"/>
      <xs:element name="Country" type="Country" minOccurs="0"/>
      <xs:element name="Goods" type="GoodsType" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="BuyersType">
    <xs:sequence>
      <xs:element name="Buyer" type="BuyerType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <!-- ============================================================
       Headers
       ============================================================ -->

  <xs:simpleType name="TransportOperationType">
    <xs:restriction base="xs:integer">
      <xs:enumeration value="9"/>
      <xs:enumeration value="10"/>
      <xs:enumeration value="13"/>
      <xs:enumeration value="14"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="TransportHeaderType">
    <xs:all>
      <xs:element name="Version" type="Text10" minOccurs="0">
        <xs:annotation><xs:documentation>Accepted but ignored by the hub.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="FiscalRegNo" type="Text13" minOccurs="0">
        <xs:annotation><xs:documentation>Accepted but ignored by the hub.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="TransportDate" type="DateTime" minOccurs="0">
        <xs:annotation><xs:documentation>Accepted but ignored by the hub.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="OperationType" type="TransportOperationType">
        <xs:annotation><xs:documentation>9=Import, 10=Export, 13=Internal, 14=ThirdCountry.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="InternalReference" type="Text200" minOccurs="0">
        <xs:annotation><xs:documentation>Becomes the job folder name and is echoed back in the result file.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="UIN" type="Text13" minOccurs="0">
        <xs:annotation><xs:documentation>Only when correcting an already submitted declaration.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="TaxpayerIdent" type="Bulstat" minOccurs="0">
        <xs:annotation><xs:documentation>Not read by the hub yet; the taxpayer comes from Settings &gt; NRA.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="TaxpayerIdentType" type="TaxpayerIdentType" minOccurs="0">
        <xs:annotation><xs:documentation>Not read by the hub yet; the taxpayer comes from Settings &gt; NRA.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="AnnulHeaderType">
    <xs:all>
      <xs:element name="Version" type="Text10" minOccurs="0"/>
      <xs:element name="FiscalRegNo" type="Text13" minOccurs="0"/>
      <xs:element name="OperationType" minOccurs="0">
        <xs:simpleType>
          <xs:restriction base="xs:integer">
            <xs:enumeration value="11"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="InternalReference" type="Text200" minOccurs="0"/>
      <xs:element name="TaxpayerIdent" type="Bulstat" minOccurs="0"/>
      <xs:element name="TaxpayerIdentType" type="TaxpayerIdentType" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="ConfirmHeaderType">
    <xs:all>
      <xs:element name="Version" type="Text10" minOccurs="0"/>
      <xs:element name="FiscalRegNo" type="Text13" minOccurs="0"/>
      <xs:element name="OperationType" minOccurs="0">
        <xs:simpleType>
          <xs:restriction base="xs:integer">
            <xs:enumeration value="12"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="InternalReference" type="Text200" minOccurs="0"/>
      <xs:element name="TaxpayerIdent" type="Bulstat" minOccurs="0"/>
      <xs:element name="TaxpayerIdentType" type="TaxpayerIdentType" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <!-- ============================================================
       Root elements
       ============================================================ -->

  <xs:element name="HFRGBULGARIA">
    <xs:annotation>
      <xs:documentation>
        Transport declarations: Import (9), Export (10), Internal Transport (13), Third Country (14).
        Fill only the elements relevant to the chosen OperationType; see field-mapping.md.
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:all>
        <xs:element name="Header" type="TransportHeaderType"/>

        <!-- Recipient: Import, Export -->
        <xs:element name="RecipientIdent" type="SubjectIdent" minOccurs="0"/>
        <xs:element name="RecipientIdentType" type="MainIdentType" minOccurs="0"/>

        <!-- Shipper: Internal, ThirdCountry -->
        <xs:element name="ShipperIdent" type="SubjectIdent" minOccurs="0"/>
        <xs:element name="ShipperIdentType" type="MainIdentType" minOccurs="0"/>

        <!-- Export -->
        <xs:element name="IsSr" type="Boolean" minOccurs="0"/>

        <!-- ThirdCountry -->
        <xs:element name="CustomsOffice" type="Text8" minOccurs="0"/>
        <xs:element name="CustomsDocument" type="Text20" minOccurs="0"/>
        <xs:element name="CustomsDate" type="Date" minOccurs="0"/>
        <xs:element name="CustomsTime" type="Time" minOccurs="0"/>
        <xs:element name="CustomsLocation" type="Text8" minOccurs="0"/>

        <!-- Carrier -->
        <xs:element name="HasCarrier" type="Boolean" minOccurs="0"/>
        <xs:element name="CarrierIsPerson" type="Boolean" minOccurs="0"/>
        <xs:element name="CarrierName" type="Text200" minOccurs="0"/>
        <xs:element name="CarrierIdent" type="Vin" minOccurs="0"/>
        <xs:element name="CarrierIdentType" type="CarrierIdentType" minOccurs="0"/>

        <!-- Organizer -->
        <xs:element name="HasOrganizer" type="Boolean" minOccurs="0"/>
        <xs:element name="OrganizerIsPerson" type="Boolean" minOccurs="0"/>
        <xs:element name="OrganizerName" type="Text200" minOccurs="0"/>
        <xs:element name="OrganizerIdent" type="Vin" minOccurs="0"/>
        <xs:element name="OrganizerIdentType" type="CarrierIdentType" minOccurs="0"/>

        <!-- Vehicle -->
        <xs:element name="RegVehicle" type="RegPlate" minOccurs="0"/>
        <xs:element name="RegTrailer1" type="RegPlate" minOccurs="0"/>
        <xs:element name="RegTrailer2" type="RegPlate" minOccurs="0"/>

        <!-- Loading address: Export, Internal -->
        <xs:element name="LoadLocalAddress" type="Text100" minOccurs="0"/>
        <xs:element name="LoadStreet" type="Text100" minOccurs="0"/>
        <xs:element name="LoadNumber" type="Text5" minOccurs="0"/>
        <xs:element name="LoadEkatte" type="PostalCode" minOccurs="0"/>
        <xs:element name="LoadDate" type="Date" minOccurs="0"/>
        <xs:element name="LoadTime" type="Time" minOccurs="0"/>

        <!-- Transhipment: Import, Export, Internal -->
        <xs:element name="IsTranshipment" type="Boolean" minOccurs="0"/>
        <xs:element name="TranshipmentTransportType" type="TransportType" minOccurs="0"/>
        <xs:element name="TranshipmentDate" type="Date" minOccurs="0"/>
        <xs:element name="TranshipmentTime" type="Time" minOccurs="0"/>
        <xs:element name="TranshipmentLocalAddress" type="Text100" minOccurs="0"/>
        <xs:element name="TranshipmentStreet" type="Text100" minOccurs="0"/>
        <xs:element name="TranshipmentNumber" type="Text5" minOccurs="0"/>
        <xs:element name="TranshipmentEkatte" type="PostalCode" minOccurs="0"/>

        <!-- Transfer: all four types -->
        <xs:element name="IsTransfer" type="Boolean" minOccurs="0"/>
        <xs:element name="TransferLocalAddress" type="Text100" minOccurs="0"/>
        <xs:element name="TransferStreet" type="Text100" minOccurs="0"/>
        <xs:element name="TransferNumber" type="Text5" minOccurs="0"/>
        <xs:element name="TransferEkatte" type="PostalCode" minOccurs="0"/>
        <xs:element name="TransferDate" type="Date" minOccurs="0"/>
        <xs:element name="TransferTime" type="Time" minOccurs="0"/>
        <xs:element name="TransCarrierIsPerson" type="Boolean" minOccurs="0"/>
        <xs:element name="TransCarrierName" type="Text200" minOccurs="0"/>
        <xs:element name="TransCarrierIdent" type="Vin" minOccurs="0"/>
        <xs:element name="TransCarrierIdentType" type="CarrierIdentType" minOccurs="0"/>
        <xs:element name="TransRegVehicle" type="RegPlate" minOccurs="0"/>
        <xs:element name="TransRegTrailer1" type="RegPlate" minOccurs="0"/>
        <xs:element name="TransRegTrailer2" type="RegPlate" minOccurs="0"/>

        <!-- Collections -->
        <xs:element name="Counterparties" type="CounterpartiesType" minOccurs="0"/>
        <xs:element name="Buyers" type="BuyersType" minOccurs="0"/>

        <!-- Contact info: optional, filled from the signer settings when omitted -->
        <xs:element name="ContactName" type="Text200" minOccurs="0"/>
        <xs:element name="ContactPhoneCode" type="PhoneCode" minOccurs="0"/>
        <xs:element name="ContactPhone" type="Text10" minOccurs="0"/>
        <xs:element name="ContactEmail" type="Email" minOccurs="0"/>
        <xs:element name="DeclarantName" type="Text200" minOccurs="0"/>
      </xs:all>
    </xs:complexType>
  </xs:element>

  <xs:element name="HFRGAnnul">
    <xs:annotation>
      <xs:documentation>
        Cancellation (11). Routed by root element name; IsCorrect is always set to true by the hub.
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:all>
        <xs:element name="Header" type="AnnulHeaderType" minOccurs="0"/>
        <xs:element name="Ident" type="SubjectIdent" minOccurs="0"/>
        <xs:element name="IdentType" type="MainIdentType" minOccurs="0"/>
        <xs:element name="UIN" type="Text13" minOccurs="0">
          <xs:annotation><xs:documentation>UIN of the declaration being cancelled. Read from the root, not from the Header.</xs:documentation></xs:annotation>
        </xs:element>
      </xs:all>
    </xs:complexType>
  </xs:element>

  <xs:element name="HFRGConfirm">
    <xs:annotation>
      <xs:documentation>
        Confirmation (12). Routed by root element name; IsCorrect is always set to true by the hub.
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:all>
        <xs:element name="Header" type="ConfirmHeaderType" minOccurs="0"/>
        <xs:element name="Ident" type="Bulstat" minOccurs="0"/>
        <xs:element name="IdentType" type="MainIdentType" minOccurs="0"/>
        <xs:element name="IsReceived" type="Boolean" minOccurs="0"/>
        <xs:element name="UinReceived" type="Text13" minOccurs="0"/>
        <xs:element name="IsSent" type="Boolean" minOccurs="0"/>
        <xs:element name="UinSent" type="Text13" minOccurs="0"/>
      </xs:all>
    </xs:complexType>
  </xs:element>

</xs:schema>
