{
  "$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 and durable success requires URL/path plus stored-submission verification.",
  "oneOf": [
    {
      "$ref": "#/$defs/success"
    },
    {
      "$ref": "#/$defs/not_found"
    }
  ],
  "$defs": {
    "success": {
      "type": "object",
      "required": [
        "found",
        "receipt",
        "receipt_hash_verified",
        "receipt_url_binding_verified",
        "stored_submission_hash_verified",
        "final_status"
      ],
      "properties": {
        "found": {
          "const": true
        },
        "receipt": {
          "type": "object"
        },
        "receipt_hash_verified": {
          "const": true
        },
        "receipt_url_binding_verified": {
          "const": true,
          "description": "The requested receipt ID, receipt path, and receipt-internal identifiers were verified to be canonically bound."
        },
        "stored_submission_hash_verified": {
          "type": "boolean",
          "description": "True only when the durable stored submission was read and its canonical SHA-256 matched the immutable receipt. False is permitted only for an explicitly warned process-local dry-run/cache fallback."
        },
        "final_status": {
          "$ref": "#/$defs/final_status"
        },
        "envelope_warnings": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "message"
                ],
                "properties": {
                  "code": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  },
                  "retryable": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              }
            ]
          },
          "description": "Non-fatal warnings about the receipt envelope. Not part of the immutable receipt hash domain."
        }
      },
      "additionalProperties": true
    },
    "not_found": {
      "type": "object",
      "required": [
        "found",
        "diagnostics"
      ],
      "properties": {
        "found": {
          "const": false
        },
        "diagnostic_code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "diagnostics": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "code",
              "severity",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "severity": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        }
      },
      "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-XXXXXXXXX record ID if appended, null otherwise."
        },
        "final_record_sha256": {
          "type": [
            "string",
            "null"
          ]
        },
        "rejection_path": {
          "type": [
            "string",
            "null"
          ],
          "description": "Path to the rejection record if rejected, null otherwise."
        },
        "rejection_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": true
    }
  }
}
