{
  "$schema": "http://json-schema.org/draft-04/schema",
  "title": "JSON Schema for B2B Supplier Despatch Object",

  "definitions": {
    "SupplierDespatchLineObject": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "DespatchQuantity": {
          "type": "number"
        },
        "SupplierDespatchRef": { //Suppliers internal despatch reference
          "type": [
            "string",
            "null"
          ]
        },
        "OrderQuantity": {
          "type": "number"
        },
        "SupplierItemCode": { //SKU - either this and/or B2BSizeID should be sent
          "type": [
            "string",
            "null"
          ]
        },
        "B2BSizeID": { //Zero if unknown in which case Supplier ItemCode must be sent.
          "type": "integer"
        },
        "UnitCost": { //Zero is acceptable
          "type": "number"
        },
        "B2BSupplierOrderID": { //B2B Purchase Order Reference - can be zero if B2BSalesOrderID or SuppliersOrderReference is sent
          "type": "integer"
        },
        "B2BSalesOrderID": { //B2B Sales Order Reference - can be 0 if B2BSupplierOrderID or SuppliersOrderRef is sent
          "type": "integer"
        },
        "OrderStatus": { //Value generally company dependent but will be automatically calculated if set to zero
          "type": "integer"
        },
        "SuppliersOrderRef": { //Suppliers Internal Reference for the order - often supplied in order acknowledgement. Can be NULL/Empty String if B2BSupplierOrderID or B2BSalesOrderID is sent
          "type": [
            "string",
            "null"
          ]
        },
        "ObjectType": { // "Despatch" for a despatch
          "type": [
            "string",
            "null"
          ]
        },
        "ShopID": { //Used by B2B to identify shop. This or ClientCode should be supplied
          "type": "integer"
        },
        "CompanyID": { //B2B Internal ID of Customer for whom B2B are operating the shop
          "type": "integer"
        },
        "ClientCode": { //Alternative to ShopID
          "type": [
            "string",
            "null"
          ]
        },
        "SupplierID": { //Suppliers UniqueID within B2B Systems
          "type": "integer"
        },
        "Signature": { //AES256 Hash of SignedString + Supplier Secret Key
          "type": [
            "string",
            "null"
          ]
        },
        "SignedString": { //String concatinated from key fields
          "type": [
            "string",
            "null"
          ]
        },
        "DateTimeStamp": { //if "LastUpdated" is provide 0 else date and time in Julian that the selected item was updated
          "type": "number"
        },
        "LastUpdated": { //If not supplied will be calculated from the DateTimeStamp
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "DespatchQuantity",
        "SupplierDespatchRef",
        "OrderQuantity",
        "SupplierItemCode",
        "B2BSizeID",
        "UnitCost",
        "B2BSupplierOrderID",
        "B2BSalesOrderID",
        "OrderStatus",
        "SuppliersOrderRef",
        "ObjectType",
        "ShopID",
        "CompanyID",
        "ClientCode",
        "SupplierID",
        "Signature",
        "SignedString",
        "DateTimeStamp",
        "LastUpdated"
      ]
    }
  },
  "type": "object",
  "properties": {
    "SupplierDespatchRef": { //As above
      "type": [
        "string",
        "null"
      ]
    },
    "DespatchDate": {
      "type": "string",
      "format": "date-time"
    },
    "TrackingNumber": {
      "type": [
        "string",
        "null"
      ]
    },
    "PostCode": {
      "type": [
        "string",
        "null"
      ]
    },
    "BranchCode": {
      "type": [
        "string",
        "null"
      ]
    },
    "DeliveryTimeStamp": { //optional - zero acceptable
      "type": "number"
    },
    "DespatchTimeStamp": { //optional - zero acceptable
      "type": "number"
    },
    "DeliveryDate": { 
      "type": "string",
      "format": "date-time"
    },
    "DespatchLines": { //Array as per first definition
      "type": [
        "array",
        "null"
      ],
      "items": {
        "$ref": "#/definitions/SupplierDespatchLineObject"
      }
    },
    "ReceivedByName": {
      "type": [
        "string",
        "null"
      ]
    },
    "ParcelCode": { //additonal reference for multi parcel single tracking number shippment
      "type": [
        "string",
        "null"
      ]
    },
    "ObjectType": { //"DespatchHeader"
      "type": [
        "string",
        "null"
      ]
    },
    "ShopID": { //As per earlier definition
      "type": "integer"
    },
    "CompanyID": { //As per earlier definition
      "type": "integer"
    },
    "ClientCode": { //As per earlier definition
      "type": [
        "string",
        "null"
      ]
    },
    "SupplierID": { //As per earlier definition
      "type": "integer"
    },
    "Signature": { //As per earlier definition
      "type": [
        "string",
        "null"
      ]
    },
    "SignedString": { //As per earlier definition
      "type": [
        "string",
        "null"
      ]
    },
    "DateTimeStamp": { //As per earlier definition
      "type": "number"
    },
    "LastUpdated": { //As per earlier definition
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "SupplierDespatchRef",
    "DespatchDate",
    "TrackingNumber",
    "PostCode",
    "BranchCode",
    "DeliveryTimeStamp",
    "DespatchTimeStamp",
    "DeliveryDate",
    "DespatchLines",
    "ReceivedByName",
    "ParcelCode",
    "ObjectType",
    "ShopID",
    "CompanyID",
    "ClientCode",
    "SupplierID",
    "Signature",
    "SignedString",
    "DateTimeStamp",
    "LastUpdated"
  ]
}