{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/infinihash-com/json-schema/infinihash-com-policy-decision-schema.json",
  "title": "PolicyDecision",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/infinihash-com-policy-api-openapi.yml#/components/schemas/PolicyDecision",
  "type": "object",
  "required": [
    "verification_required",
    "reason_code",
    "matched_rule",
    "ruleset_version",
    "evaluated_at",
    "fail_closed",
    "obligation",
    "ruleset_source"
  ],
  "properties": {
    "verification_required": {
      "$ref": "#/$defs/PolicyOutcome"
    },
    "reason_code": {
      "type": "string",
      "description": "P00 default, P01-P08 rule reasons (custom rules may set others), P99 fail-closed."
    },
    "matched_rule": {
      "type": [
        "string",
        "null"
      ],
      "description": "Id of the rule that matched, null when the ruleset default applied."
    },
    "ruleset_version": {
      "type": [
        "integer",
        "null"
      ]
    },
    "evaluated_at": {
      "type": "string",
      "format": "date-time"
    },
    "fail_closed": {
      "type": "boolean",
      "description": "true when evaluation failed and the most restrictive outcome (full_idv) was returned."
    },
    "obligation": {
      "allOf": [
        {
          "$ref": "#/$defs/PolicyObligation"
        }
      ],
      "description": "Deferred obligation recorded for a dl_image outcome; null otherwise."
    },
    "ruleset_source": {
      "type": "string",
      "enum": [
        "default",
        "tenant",
        "error"
      ]
    },
    "errors": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Present on fail-closed decisions caused by an invalid ruleset or evaluation error."
    }
  },
  "$defs": {
    "PolicyObligation": {
      "type": "object",
      "required": [
        "id",
        "type",
        "status",
        "due_by",
        "on_lapse",
        "card_ref",
        "existing"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "dl_image"
          ]
        },
        "status": {
          "type": "string",
          "description": "open on creation (or the status of the existing open obligation)."
        },
        "due_by": {
          "type": "string",
          "format": "date-time"
        },
        "on_lapse": {
          "type": "string",
          "enum": [
            "flag",
            "block",
            "escalate"
          ]
        },
        "card_ref": {
          "type": [
            "string",
            "null"
          ]
        },
        "existing": {
          "type": "boolean",
          "description": "true when an already-open obligation for this card was returned instead of creating a new one."
        }
      }
    },
    "PolicyOutcome": {
      "type": "string",
      "enum": [
        "none",
        "sms_confirmation",
        "dl_number",
        "dl_image",
        "liveness",
        "full_idv"
      ],
      "description": "Verification step required. Ordered from least to most restrictive."
    }
  }
}