{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.ectropy.ai/flow/logistic-unit.schema.json",
  "title": "Logistic Unit",
  "version": "0.2.0",
  "description": "A pallet, bundle, kit or single product on site: contents by GTIN or BPC product or assembly, quantity in UN/CEFACT Rec 20 units, mass with its basis. Its state is the projection of its events, never stored here.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "unit",
    "contents"
  ],
  "properties": {
    "unit": {
      "$ref": "https://schemas.ectropy.ai/flow/flow-common.schema.json#/definitions/unitId"
    },
    "kind": {
      "enum": [
        "pallet",
        "bundle",
        "kit",
        "package",
        "item",
        "returnable"
      ]
    },
    "contents": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "quantity",
          "uom"
        ],
        "properties": {
          "gtin": {
            "type": "string",
            "pattern": "^[0-9]{8,14}$"
          },
          "bpcProduct": {
            "type": "string"
          },
          "bpcAssembly": {
            "type": "string"
          },
          "quantity": {
            "type": "number",
            "minimum": 0
          },
          "uom": {
            "$ref": "https://schemas.ectropy.ai/flow/flow-common.schema.json#/definitions/uom"
          }
        },
        "anyOf": [
          {
            "required": [
              "gtin"
            ]
          },
          {
            "required": [
              "bpcProduct"
            ]
          },
          {
            "required": [
              "bpcAssembly"
            ]
          }
        ]
      }
    },
    "mass": {
      "$ref": "https://schemas.ectropy.ai/flow/flow-common.schema.json#/definitions/figure"
    },
    "origin": {
      "type": "string"
    },
    "packaging": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "material": {
          "type": "string"
        },
        "massKg": {
          "type": "number",
          "minimum": 0
        },
        "returnable": {
          "type": "boolean"
        }
      }
    }
  }
}
