{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "trinityaccord.record-chain-submit-response.v1",
  "title": "Record-Chain Submit Response",
  "description": "Schema for the response from POST /record-chain/submit. The receipt is not a final chain record.",
  "type": "object",
  "required": ["accepted", "submitted", "receipt_id", "record_type", "submission_sha256", "received_raw_body_sha256", "pending_file_path", "intake_submission_path", "receipt_path", "server_created_at", "append_status", "diagnostics", "warnings", "boundary", "created_pending_records"],
  "properties": {
    "accepted": { "type": "boolean" },
    "submitted": { "type": "boolean" },
    "receipt_id": { "type": "string", "pattern": "^rcg-[0-9]{8}-[a-f0-9]{12}(-[0-9]{2})?$" },
    "record_type": {
      "type": "string",
      "enum": ["echo", "verification", "guardian_application", "guardian_retirement", "guardian_key_rotation", "propagation", "correction", "classification_update", "context_insufficient_notice"]
    },
    "submission_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "received_raw_body_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "pending_file_path": { "type": "string" },
    "intake_submission_path": { "type": "string" },
    "receipt_path": { "type": "string" },
    "server_created_at": { "type": "string", "format": "date-time" },
    "append_status": { "type": "string", "enum": ["queued", "appended", "rejected", "duplicate"] },
    "receipt": { "type": "object" },
    "diagnostics": {
      "type": "array",
      "items": { "$ref": "#/$defs/diagnostic" }
    },
    "warnings": {
      "type": "array",
      "items": { "type": "string" }
    },
    "boundary": {
      "type": "object",
      "required": ["receipt_is_not_authority", "receipt_is_not_attestation", "receipt_is_not_final_chain_record", "record_chain_append_is_server_side"],
      "properties": {
        "receipt_is_not_authority": { "const": true },
        "receipt_is_not_attestation": { "const": true },
        "receipt_is_not_final_chain_record": { "const": true },
        "record_chain_append_is_server_side": { "const": true }
      }
    },
    "created_pending_records": {
      "type": "array",
      "items": { "type": "string" },
      "description": "List of pending file paths created by this submission. Contains the primary record path, and optionally a linked guardian_application path."
    }
  },
  "additionalProperties": true,
  "$defs": {
    "diagnostic": {
      "type": "object",
      "required": ["code", "severity", "message"],
      "properties": {
        "code": { "type": "string" },
        "severity": { "type": "string", "enum": ["error", "warning", "info"] },
        "field": { "type": "string" },
        "message": { "type": "string" },
        "meaning": { "type": "string" },
        "suggested_fix": { "type": "string" },
        "help_url": { "type": "string", "format": "uri" },
        "retry_allowed": { "type": "boolean" }
      }
    }
  }
}
