{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tekcapitol.com/schema/check-write-response/v1/check-write-response.v1.json",
  "title": "Check Write Response v1",
  "description": "Public response contract for POST /v1/check-write. Check Write evaluates caller-supplied authority and control evidence against configured requirements.",
  "type": "object",
  "additionalProperties": true,
  "required": ["decision", "allowed", "reason", "reason_code", "schemaVersion"],
  "properties": {
    "success": { "type": "boolean" },
    "decision": {
      "type": "string",
      "enum": ["allow", "pause", "block"]
    },
    "allowed": { "type": "boolean" },
    "reason": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable explanation. Always present on decision responses (including allow)."
    },
    "reason_code": {
      "type": "string",
      "minLength": 1,
      "description": "Stable machine-readable code (snake_case). On allow without a specific gate failure, use requirements_met."
    },
    "reasonCode": { "type": "string" },
    "decision_id": { "type": "string" },
    "decisionId": { "type": "string" },
    "audit_id": { "type": "string" },
    "auditId": { "type": "string" },
    "request_id": { "type": "string" },
    "traceId": { "type": "string" },
    "schemaVersion": { "const": "write_intent.v1" },
    "execution_status": { "type": "string" },
    "executionStatus": { "type": "string" },
    "required_controls": {
      "type": "array",
      "items": { "type": "string" }
    },
    "requiredControls": {
      "type": "array",
      "items": { "type": "string" }
    },
    "control_evaluations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "controlId": { "type": "string" },
          "present": { "type": "boolean" },
          "result": { "type": "string" },
          "source": { "type": "string" },
          "checkedAt": { "type": "string" },
          "evidenceRef": { "type": "string" },
          "fresh": { "type": "boolean" },
          "status": { "type": "string" },
          "code": { "type": "string" },
          "effect": { "type": "string", "enum": ["allow", "pause", "block"] },
          "authorityState": {
            "type": "string",
            "enum": ["valid", "stale", "expired", "revoked", "unknown"]
          }
        }
      }
    },
    "controlEvaluations": { "type": "array" },
    "profileProvenance": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "profileId": { "type": "string" },
        "profileVersion": { "type": "string" },
        "controlPackId": { "type": "string" },
        "policyRef": { "type": "string" },
        "source": { "type": "string" }
      }
    },
    "requirementProvenance": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "controlId": { "type": "string" },
          "sources": {
            "type": "array",
            "items": { "type": "string" }
          },
          "diagnosePromotion": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "source": { "type": "string" },
              "assessmentRef": { "type": "string" },
              "runRef": { "type": "string" },
              "promotedAt": { "type": "string" },
              "promotedBy": { "type": "string" },
              "status": { "type": "string" }
            }
          }
        }
      }
    },
    "writePolicy": { "type": "string", "enum": ["observe", "enforce", "block_on_mismatch"] },
    "observeMode": { "type": "boolean" },
    "enforced": { "type": "boolean" },
    "warn": { "type": "boolean" },
    "failClosed": { "type": "boolean" },
    "timestamp": { "type": "string", "format": "date-time" },
    "error": {
      "type": "object",
      "properties": {
        "code": { "type": "string" },
        "message": { "type": "string" }
      }
    }
  }
}
