{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/transport-commitment",
  "title": "TransportCommitment",
  "description": "Immutable proof that every decision required by the tender's decision policy was accepted before expiry or valid withdrawal. Proves agreement; does not prove the executing system imported the work.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "UUIDv7 resource identifier."
    },
    "resourceVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "Optimistic-concurrency counter. Commitments are create-once and immutable; this remains 1 for the life of the resource."
    },
    "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. Equal to createdAt for this create-once resource."
    },
    "externalReferences": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExternalReference" },
      "description": "Namespaced references to records in external systems (TMS, ERP, etc.)."
    },
    "acceptedTenderRevisionId": {
      "type": "string",
      "format": "uuid",
      "description": "Identifier of the specific TransportTender revision whose terms were accepted."
    },
    "requiredDecisions": {
      "type": "array",
      "description": "Decision records for every role required by the tender's decision policy.",
      "items": { "$ref": "#/$defs/DecisionRecord" },
      "minItems": 1
    },
    "acceptanceTimestamps": {
      "type": "object",
      "description": "Map of role identifier to ISO 8601 acceptance timestamp, mirroring requiredDecisions.",
      "additionalProperties": { "type": "string", "format": "date-time" }
    },
    "decisionDigest": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "Deterministic SHA-256 hex digest of the canonical accepted decision-relevant payload."
    },
    "relationshipPolicyVersion": {
      "type": "string",
      "minLength": 1,
      "description": "Version identifier of the PartnerRelationship decision policy in effect when this commitment was formed."
    },
    "resultingCapacityReservationId": {
      "type": ["string", "null"],
      "description": "Identifier of the capacity reservation or consumption resulting from this commitment, or null if none was created."
    }
  },
  "required": [
    "id",
    "resourceVersion",
    "ownerOrganizationId",
    "createdAt",
    "updatedAt",
    "acceptedTenderRevisionId",
    "requiredDecisions",
    "acceptanceTimestamps",
    "decisionDigest",
    "relationshipPolicyVersion"
  ],
  "$defs": {
    "ExternalReference": {
      "type": "object",
      "properties": {
        "system": { "type": "string" },
        "type": { "type": "string" },
        "value": { "type": "string" }
      },
      "required": ["system", "type", "value"]
    },
    "DecisionRecord": {
      "title": "DecisionRecord",
      "description": "A single accepted decision required by the tender's decision policy.",
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "description": "Role identifier for the party whose acceptance this record proves, e.g. 'ISSUER', 'EXECUTOR'."
        },
        "actorId": {
          "type": "string",
          "description": "Opaque identifier of the individual actor who recorded the acceptance."
        },
        "acceptedAt": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp at which this role's acceptance was recorded."
        }
      },
      "required": ["role", "actorId", "acceptedAt"]
    }
  }
}
