{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openfreytprotocol.example/schemas/v0/match-decision",
  "title": "MatchDecision",
  "description": "A party's accept or reject decision on a MatchProposal, including an optimistic concurrency check on the proposal version.",
  "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."
    },
    "proposalId": {
      "type": "string",
      "format": "uuid",
      "description": "Identifier of the MatchProposal this decision refers to."
    },
    "proposalVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "resourceVersion of the MatchProposal at the time this decision was submitted. Used for optimistic concurrency: the broker rejects the decision if the proposal has since been superseded."
    },
    "organizationId": {
      "type": "string",
      "description": "Opaque broker-scoped identifier of the organization submitting this decision."
    },
    "decision": {
      "type": "string",
      "enum": ["accept", "reject"],
      "description": "The party's decision on the proposal."
    },
    "decisionRole": {
      "type": "string",
      "enum": ["INITIATOR", "ACCEPTOR"],
      "description": "The role of the deciding party within the match: INITIATOR posted the offer or request that triggered the match; ACCEPTOR is the counterparty."
    },
    "reason": {
      "type": "string",
      "description": "Optional free-text reason for the decision, especially useful for rejections."
    }
  },
  "required": [
    "id",
    "resourceVersion",
    "ownerOrganizationId",
    "createdAt",
    "updatedAt",
    "proposalId",
    "proposalVersion",
    "organizationId",
    "decision",
    "decisionRole"
  ],
  "$defs": {
    "ExternalReference": {
      "type": "object",
      "properties": {
        "system": { "type": "string" },
        "type": { "type": "string" },
        "value": { "type": "string" }
      },
      "required": ["system", "type", "value"]
    }
  }
}
