{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/execution-reference",
  "title": "ExecutionReference",
  "description": "A broker record that links a confirmed match to the external trip and order identifiers created in the parties' operational systems.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "UUIDv7 resource identifier."
    },
    "resourceVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "Optimistic-concurrency counter. Incremented on every mutation."
    },
    "ownerOrganizationId": {
      "type": "string",
      "description": "Opaque broker-scoped identifier of the organization that owns this resource."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 / RFC 3339 timestamp when the resource was first created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 / RFC 3339 timestamp of the most recent mutation."
    },
    "externalReferences": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExternalReference" },
      "description": "Namespaced references to records in external systems."
    },
    "matchId": {
      "type": "string",
      "format": "uuid",
      "description": "Identifier of the MatchProposal that was accepted and led to this execution."
    },
    "externalTripRefs": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExternalReference" },
      "description": "References to trip records created in the carrier's TMS or similar operational system."
    },
    "externalOrderRefs": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExternalReference" },
      "description": "References to order records created in the shipper's ERP or order management system."
    }
  },
  "required": [
    "id",
    "resourceVersion",
    "ownerOrganizationId",
    "createdAt",
    "updatedAt",
    "matchId",
    "externalTripRefs",
    "externalOrderRefs"
  ],
  "$defs": {
    "ExternalReference": {
      "type": "object",
      "properties": {
        "system": { "type": "string" },
        "type": { "type": "string" },
        "value": { "type": "string" }
      },
      "required": ["system", "type", "value"]
    }
  }
}
