{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "trinityaccord.record-chain-receipt-response.v1",
  "title": "Record-Chain Receipt Response",
  "description": "Schema for the response from GET /record-chain/receipt/{receipt_id}. The receipt is an immutable snapshot; envelope metadata is separate.",
  "oneOf": [
    { "$ref": "#/$defs/success" },
    { "$ref": "#/$defs/not_found" }
  ],
  "$defs": {
    "success": {
      "type": "object",
      "required": ["found", "receipt", "receipt_hash_verified", "final_status"],
      "properties": {
        "found": { "const": true },
        "receipt": { "type": "object" },
        "receipt_hash_verified": { "type": "boolean" },
        "final_status": { "$ref": "#/$defs/final_status" },
        "envelope_warnings": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Non-fatal warnings about the receipt envelope (e.g. fallback lookup path). Not part of the immutable receipt hash domain."
        }
      },
      "additionalProperties": true
    },
    "not_found": {
      "type": "object",
      "required": ["found", "diagnostics"],
      "properties": {
        "found": { "const": false },
        "diagnostics": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["code", "severity", "message"],
            "properties": {
              "code": { "type": "string" },
              "severity": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      },
      "additionalProperties": true
    },
    "final_status": {
      "type": "object",
      "properties": {
        "append_status": {
          "type": "string",
          "enum": ["pending", "appended", "rejected", "unknown"]
        },
        "final_record_id": {
          "type": ["string", "null"],
          "description": "The R-XXXXXXXXXX record ID if appended, null otherwise."
        },
        "rejection_path": {
          "type": ["string", "null"],
          "description": "Path to the rejection record if rejected, null otherwise."
        }
      }
    }
  }
}
