{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/infinihash-com/json-schema/infinihash-com-policy-publish-request-schema.json",
  "title": "PolicyPublishRequest",
  "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/PolicyPublishRequest",
  "type": "object",
  "required": [
    "api_key_id",
    "ruleset"
  ],
  "properties": {
    "api_key_id": {
      "type": "string",
      "description": "API key the ruleset is published to."
    },
    "ruleset": {
      "allOf": [
        {
          "$ref": "#/$defs/PolicyRuleset"
        }
      ],
      "description": "Version must be strictly greater than the key's latest version."
    }
  },
  "$defs": {
    "PolicyOutcome": {
      "type": "string",
      "enum": [
        "none",
        "sms_confirmation",
        "dl_number",
        "dl_image",
        "liveness",
        "full_idv"
      ],
      "description": "Verification step required. Ordered from least to most restrictive."
    },
    "PolicyRule": {
      "type": "object",
      "required": [
        "id",
        "when",
        "then"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique within the ruleset."
        },
        "when": {
          "type": "object",
          "additionalProperties": true,
          "description": "field -> condition, ALL must hold. A condition is a scalar (equality) or an object of operators eq, ne, in, not_in, exists, gt, gte, lt, lte. Unknown operators never match."
        },
        "then": {
          "$ref": "#/$defs/PolicyOutcome"
        },
        "reason": {
          "type": "string",
          "description": "Reason code reported when this rule matches (e.g. P01)."
        },
        "override": {
          "type": "boolean",
          "description": "Override rules are evaluated first and can only raise the requirement; the highest matching override wins."
        }
      }
    },
    "PolicyRuleset": {
      "type": "object",
      "required": [
        "version",
        "default",
        "rules"
      ],
      "properties": {
        "version": {
          "type": "integer",
          "minimum": 1
        },
        "default": {
          "$ref": "#/$defs/PolicyOutcome"
        },
        "rules": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PolicyRule"
          }
        },
        "obligations": {
          "type": "object",
          "description": "Deferred-obligation config, keyed by obligation type. Only `dl_image` is allowed.",
          "properties": {
            "dl_image": {
              "type": "object",
              "properties": {
                "due_hours": {
                  "type": "number",
                  "description": "Default 48.",
                  "exclusiveMinimum": 0
                },
                "on_lapse": {
                  "type": "string",
                  "enum": [
                    "flag",
                    "block",
                    "escalate"
                  ],
                  "description": "Default block."
                }
              }
            }
          },
          "additionalProperties": false
        }
      }
    }
  }
}