{
  "$defs": {
    "DocumentReference": {
      "additionalProperties": false,
      "properties": {
        "identifier": {
          "$ref": "#/$defs/Identifier"
        },
        "document_type": {
          "maxLength": 200,
          "minLength": 1,
          "title": "Document Type",
          "type": "string"
        },
        "status": {
          "enum": [
            "issued",
            "replaced",
            "cancelled"
          ],
          "title": "Status",
          "type": "string"
        },
        "issuer_id": {
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
          "title": "Issuer Id",
          "type": "string"
        },
        "sha256": {
          "anyOf": [
            {
              "pattern": "^[a-f0-9]{64}$",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sha256"
        }
      },
      "required": [
        "identifier",
        "document_type",
        "status",
        "issuer_id"
      ],
      "title": "DocumentReference",
      "type": "object"
    },
    "GoodsItem": {
      "additionalProperties": false,
      "properties": {
        "identifier": {
          "$ref": "#/$defs/Identifier"
        },
        "description": {
          "maxLength": 500,
          "minLength": 1,
          "title": "Description",
          "type": "string"
        },
        "quantity": {
          "exclusiveMinimum": 0,
          "title": "Quantity",
          "type": "number"
        },
        "unit": {
          "maxLength": 20,
          "minLength": 1,
          "title": "Unit",
          "type": "string"
        }
      },
      "required": [
        "identifier",
        "description",
        "quantity",
        "unit"
      ],
      "title": "GoodsItem",
      "type": "object"
    },
    "Identifier": {
      "additionalProperties": false,
      "properties": {
        "scheme": {
          "maxLength": 200,
          "minLength": 1,
          "title": "Scheme",
          "type": "string"
        },
        "value": {
          "maxLength": 200,
          "minLength": 1,
          "title": "Value",
          "type": "string"
        }
      },
      "required": [
        "scheme",
        "value"
      ],
      "title": "Identifier",
      "type": "object"
    },
    "Journey": {
      "additionalProperties": false,
      "properties": {
        "journey_id": {
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
          "title": "Journey Id",
          "type": "string"
        },
        "trade_flow": {
          "enum": [
            "import",
            "export",
            "interprovincial"
          ],
          "title": "Trade Flow",
          "type": "string"
        },
        "origin": {
          "$ref": "#/$defs/Location"
        },
        "destination": {
          "$ref": "#/$defs/Location"
        }
      },
      "required": [
        "journey_id",
        "trade_flow",
        "origin",
        "destination"
      ],
      "title": "Journey",
      "type": "object"
    },
    "Location": {
      "additionalProperties": false,
      "properties": {
        "identifier": {
          "$ref": "#/$defs/Identifier"
        },
        "name": {
          "maxLength": 200,
          "minLength": 1,
          "title": "Name",
          "type": "string"
        },
        "node_type": {
          "enum": [
            "port",
            "terminal",
            "warehouse",
            "supplier",
            "receiver",
            "facility"
          ],
          "title": "Node Type",
          "type": "string"
        },
        "country": {
          "pattern": "^[A-Z]{2}$",
          "title": "Country",
          "type": "string"
        },
        "subdivision": {
          "anyOf": [
            {
              "maxLength": 16,
              "minLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Subdivision"
        }
      },
      "required": [
        "identifier",
        "name",
        "node_type",
        "country"
      ],
      "title": "Location",
      "type": "object"
    },
    "Shipment": {
      "additionalProperties": false,
      "properties": {
        "identifier": {
          "$ref": "#/$defs/Identifier"
        },
        "goods": {
          "items": {
            "$ref": "#/$defs/GoodsItem"
          },
          "maxItems": 100,
          "minItems": 1,
          "title": "Goods",
          "type": "array"
        },
        "transport_legs": {
          "items": {
            "$ref": "#/$defs/TransportLeg"
          },
          "maxItems": 30,
          "minItems": 1,
          "title": "Transport Legs",
          "type": "array"
        }
      },
      "required": [
        "identifier",
        "goods",
        "transport_legs"
      ],
      "title": "Shipment",
      "type": "object"
    },
    "SupplyChainEvent": {
      "additionalProperties": false,
      "properties": {
        "event_type": {
          "enum": [
            "planned",
            "departed",
            "arrived",
            "transferred",
            "stored",
            "released",
            "delivered",
            "document_issued",
            "corrected"
          ],
          "title": "Event Type",
          "type": "string"
        },
        "occurred_at": {
          "format": "date-time",
          "title": "Occurred At",
          "type": "string"
        },
        "location": {
          "$ref": "#/$defs/Location"
        },
        "leg_id": {
          "anyOf": [
            {
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Leg Id"
        },
        "authority": {
          "maxLength": 200,
          "minLength": 1,
          "title": "Authority",
          "type": "string"
        },
        "release_scope": {
          "anyOf": [
            {
              "enum": [
                "customs",
                "carrier",
                "terminal",
                "collection"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Release Scope"
        }
      },
      "required": [
        "event_type",
        "occurred_at",
        "location",
        "authority"
      ],
      "title": "SupplyChainEvent",
      "type": "object"
    },
    "TransportLeg": {
      "additionalProperties": false,
      "properties": {
        "leg_id": {
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
          "title": "Leg Id",
          "type": "string"
        },
        "mode": {
          "enum": [
            "ship",
            "rail",
            "truck"
          ],
          "title": "Mode",
          "type": "string"
        },
        "operator_id": {
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
          "title": "Operator Id",
          "type": "string"
        },
        "origin": {
          "$ref": "#/$defs/Location"
        },
        "destination": {
          "$ref": "#/$defs/Location"
        }
      },
      "required": [
        "leg_id",
        "mode",
        "operator_id",
        "origin",
        "destination"
      ],
      "title": "TransportLeg",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "properties": {
    "schema_version": {
      "const": "0.1.0",
      "title": "Schema Version",
      "type": "string"
    },
    "message_id": {
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
      "title": "Message Id",
      "type": "string"
    },
    "message_type": {
      "enum": [
        "shipment_event",
        "document_notice",
        "correction"
      ],
      "title": "Message Type",
      "type": "string"
    },
    "issuer_id": {
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
      "title": "Issuer Id",
      "type": "string"
    },
    "recipient_ids": {
      "items": {
        "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
        "type": "string"
      },
      "maxItems": 50,
      "minItems": 1,
      "title": "Recipient Ids",
      "type": "array"
    },
    "created_at": {
      "format": "date-time",
      "title": "Created At",
      "type": "string"
    },
    "journey": {
      "$ref": "#/$defs/Journey"
    },
    "shipment": {
      "$ref": "#/$defs/Shipment"
    },
    "event": {
      "$ref": "#/$defs/SupplyChainEvent"
    },
    "documents": {
      "items": {
        "$ref": "#/$defs/DocumentReference"
      },
      "maxItems": 50,
      "title": "Documents",
      "type": "array"
    },
    "supersedes": {
      "anyOf": [
        {
          "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Supersedes"
    }
  },
  "required": [
    "schema_version",
    "message_id",
    "message_type",
    "issuer_id",
    "recipient_ids",
    "created_at",
    "journey",
    "shipment",
    "event"
  ],
  "title": "ExchangeMessage",
  "type": "object",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://scdx.ca/schemas/exchange-message-0.1.0.json",
  "description": "Experimental SCDx profile 0.1.0; not a claim of conformance to third-party standards."
}
