{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "$id": "https://www.agentkind.org/protocol/settlement/v0.1/schemas/live-status.schema.json",
  "title": "Agentkind Settlement Protocol v0.1 — Live Status",
  "description": "LAYER 3 (CURRENT AUTHORITY / LIVE STATUS). The authoritative, live lifecycle state of a request. If live status cannot be obtained, the protocol MUST fail closed: report fail_closed=true and MUST NOT treat the request as authorized, settled, or executable. Invariant (Issue #96): when live=false, the schema MUST REJECT favorable/current-authority states that imply authorization, execution, or settlement — i.e. status MUST NOT be one of {authorized, awaiting_settlement, settled}. Only safe/non-favorable states (draft, failed, expired, revoked) are permitted when live=false. A schema that validates does not by itself prove on-chain or live state; it only proves the document is well-formed and fail-closed-correct.",
  "type": "object",
  "required": ["request_id", "status", "updated_at", "source", "live", "fail_closed"],
  "additionalProperties": false,
  "properties": {
    "request_id": { "type": "string", "pattern": "^akind-req-[A-Za-z0-9._-]{4,64}$" },
    "status": {
      "enum": ["draft", "authorized", "awaiting_settlement", "settled", "failed", "expired", "revoked"]
    },
    "updated_at": { "type": "string", "format": "date-time" },
    "source": { "type": "string", "description": "Authoritative endpoint that produced this status." },
    "live": { "type": "boolean", "description": "true when obtained from a live, reachable authoritative source." },
    "fail_closed": {
      "type": "boolean",
      "description": "true when live status was unavailable and the protocol refused to assume a favorable state. MUST be true whenever live=false."
    }
  },
  "allOf": [
    {
      "if": {
        "required": ["live"],
        "properties": {
          "live": { "const": false }
        }
      },
      "then": {
        "required": ["fail_closed"],
        "properties": {
          "fail_closed": { "const": true }
        }
      }
    },
    {
      "comment": "Issue #96 fail-closed invariant: live=false forbids favorable states.",
      "if": {
        "required": ["live", "status"],
        "properties": {
          "live": { "const": false },
          "status": { "enum": ["authorized", "awaiting_settlement", "settled"] }
        }
      },
      "then": false
    }
  ]
}
