<?xml version="1.0" encoding="UTF-8"?>
<!--
  Jakamo RFQ extension for UBL 2.3 RequestForQuotation documents.

  The RFQ features that UBL 2.3 has no element for are carried in a UBL extension in this namespace:
  several suppliers on one RFQ, suppliers that are not Jakamo companies, leaving the RFQ in draft state,
  creating the RFQ from an RFQ template, and three line fields.

  This schema is published so that you can validate your messages locally. Jakamo does not validate the
  extension against it: the extension content is outside the UBL schemas, and Jakamo checks it while it
  reads the message, which gives a message that names the element and the value that is wrong. A document
  that is valid against this schema and against the OASIS UBL 2.3 schemas is accepted, apart from the
  content rules of the API documentation, such as the mappings the identifiers have to match.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jak="urn:jakamo:rfq:2"
            xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
            xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
            targetNamespace="urn:jakamo:rfq:2"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            version="2.0">

  <xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
              schemaLocation="https://docs.oasis-open.org/ubl/os-UBL-2.3/xsd/common/UBL-CommonAggregateComponents-2.3.xsd"/>
  <xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
              schemaLocation="https://docs.oasis-open.org/ubl/os-UBL-2.3/xsd/common/UBL-CommonBasicComponents-2.3.xsd"/>

  <!-- ===== Document extension ===== -->

  <xsd:element name="Rfq" type="jak:RfqType">
    <xsd:annotation>
      <xsd:documentation>
        The Jakamo data of the RFQ. Goes in the ExtensionContent of a UBLExtension of the document, in a
        UBLExtension whose ExtensionURI is urn:jakamo:rfq:2.
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>

  <xsd:complexType name="RfqType">
    <xsd:sequence>
      <xsd:element name="Publish" type="xsd:boolean" minOccurs="0" maxOccurs="1">
        <xsd:annotation>
          <xsd:documentation>
            Should the RFQ be published to the suppliers. False leaves it in draft state for a purchaser
            to publish in Jakamo. Published when the element is left out.
          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="TemplateId" type="jak:UuidType" minOccurs="0" maxOccurs="1">
        <xsd:annotation>
          <xsd:documentation>
            The identifier of the RFQ template the new RFQ is created from. Read only when a new RFQ is
            created. The identifier of every template is shown in the Jakamo RFQ settings.
          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element ref="cac:SellerSupplierParty">
          <xsd:annotation>
            <xsd:documentation>
              A supplier in addition to the one of the document. The UBL party is read exactly as the
              SellerSupplierParty of the document itself, so the identifier goes in
              Party/PartyIdentification/ID, and Party/Contact/ElectronicMail alone names a supplier that
              is not a Jakamo company.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="Supplier" type="jak:SupplierType">
          <xsd:annotation>
            <xsd:documentation>
              A supplier in addition to the one of the document, in the shorter Jakamo form. The UBL
              cac:SellerSupplierParty above is the preferred way to give one.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
      </xsd:choice>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="SupplierType">
    <xsd:sequence>
      <xsd:element ref="cbc:ID" minOccurs="1" maxOccurs="1">
        <xsd:annotation>
          <xsd:documentation>
            The identifier of the supplier: a company mapping, or an email address with schemeID="EMAIL"
            for a supplier that is not a Jakamo company. Any other schemeID is rejected.
          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <!-- ===== Line extension ===== -->

  <xsd:element name="Line" type="jak:LineType">
    <xsd:annotation>
      <xsd:documentation>
        The Jakamo data of one RFQ line. Goes in the ExtensionContent of a UBLExtension of the
        RequestForQuotationLine.
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>

  <xsd:complexType name="LineType">
    <xsd:sequence>
      <xsd:element name="AnnualVolume" type="jak:PositiveDecimalType" minOccurs="0" maxOccurs="1">
        <xsd:annotation>
          <xsd:documentation>
            The estimated yearly volume of the item. The unit is the unit of the line, from
            LineItem/Quantity/@unitCode, so the element takes no attributes.
          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="PriceListGroup" type="jak:PriceListGroupType" minOccurs="0" maxOccurs="1">
        <xsd:annotation>
          <xsd:documentation>The price list group of the item.</xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="AdditionalQuantity" type="jak:PositiveDecimalType" minOccurs="0" maxOccurs="unbounded">
        <xsd:annotation>
          <xsd:documentation>
            One more quantity the supplier is asked to quote for, on top of LineItem/Quantity, which UBL
            allows only once per line. The unit is the unit of the line, so the element takes no
            attributes.
          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <!-- ===== Types ===== -->

  <xsd:simpleType name="UuidType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="PositiveDecimalType">
    <xsd:restriction base="xsd:decimal">
      <xsd:minExclusive value="0"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="PriceListGroupType">
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1"/>
      <xsd:maxLength value="100"/>
    </xsd:restriction>
  </xsd:simpleType>

</xsd:schema>
