{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rctp.dev/schemas/deal.schema.json",
  "title": "Deal",
  "description": "A deal created by redeeming a checkout (POST /deals). status is derived from the deal events: open → funds_held → accepted → released; or funds_held → rejected → (returned →) refunded.",
  "type": "object",
  "properties": {
    "deal_id": {
      "$ref": "common.schema.json#/$defs/DealId"
    },
    "offer_id": {
      "$ref": "common.schema.json#/$defs/OfferId"
    },
    "negotiation_id": {
      "$ref": "common.schema.json#/$defs/NegotiationId"
    },
    "listing_id": {
      "$ref": "common.schema.json#/$defs/ListingId"
    },
    "listing_hash": {
      "$ref": "common.schema.json#/$defs/Digest"
    },
    "deal_terms": {
      "$ref": "deal-terms.schema.json"
    },
    "status": {
      "type": "string",
      "enum": [
        "open",
        "funds_held",
        "accepted",
        "rejected",
        "returned",
        "released",
        "refunded"
      ]
    },
    "release_condition": {
      "$ref": "common.schema.json#/$defs/ReleaseCondition"
    },
    "deliver_within_days": {
      "type": "integer",
      "minimum": 1,
      "maximum": 365,
      "description": "From the listing's public terms: when not_received becomes possible"
    },
    "created_at": {
      "$ref": "common.schema.json#/$defs/Timestamp"
    }
  },
  "additionalProperties": false,
  "required": [
    "deal_id",
    "offer_id",
    "negotiation_id",
    "listing_id",
    "listing_hash",
    "deal_terms",
    "status",
    "release_condition",
    "created_at"
  ]
}
