{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/decide-fyi/json-schema/decide-fyi-decision-pattern-registry-schema.json",
  "title": "DecisionPatternRegistry",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/decide-fyi-policy-patterns-api-openapi.yml#/components/schemas/DecisionPatternRegistry",
  "type": "object",
  "required": [
    "ok",
    "decision_pattern_registry_version",
    "patterns",
    "registry_hash"
  ],
  "properties": {
    "ok": {
      "type": "boolean"
    },
    "decision_protocol_version": {
      "type": "string"
    },
    "decision_record_version": {
      "type": "string"
    },
    "decision_pattern_registry_version": {
      "type": "string",
      "const": "decision_pattern_registry_v1"
    },
    "source": {
      "type": "string"
    },
    "status": {
      "type": "string"
    },
    "count": {
      "type": "integer"
    },
    "patterns": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DecisionPattern"
      }
    },
    "registry_hash": {
      "type": "string"
    },
    "endpoints": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    }
  },
  "additionalProperties": true,
  "$defs": {
    "DecisionPattern": {
      "type": "object",
      "required": [
        "decision_pattern_version",
        "pattern_id",
        "policy_id",
        "pattern_hash"
      ],
      "properties": {
        "decision_pattern_version": {
          "type": "string",
          "const": "decision_pattern_v1"
        },
        "pattern_id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "category": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "summary": {
          "type": "string"
        },
        "policy_id": {
          "type": "string"
        },
        "recommended_policy_version": {
          "type": "string"
        },
        "source": {
          "type": "string"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "required_context_fields": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "recommended_context_fields": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "evidence_codes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "decision_request_template": {
          "$ref": "#/$defs/DecisionRequest"
        },
        "outcome_template": {
          "type": "object",
          "additionalProperties": true
        },
        "crm_sync_template": {
          "type": "object",
          "additionalProperties": true
        },
        "sdk_examples": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "pattern_hash": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "DecisionRequest": {
      "type": "object",
      "anyOf": [
        {
          "required": [
            "question"
          ]
        },
        {
          "required": [
            "prompt",
            "context"
          ]
        },
        {
          "required": [
            "mode",
            "rulebook",
            "context"
          ],
          "properties": {
            "mode": {
              "const": "rulebook"
            }
          }
        }
      ],
      "properties": {
        "question": {
          "type": "string"
        },
        "mode": {
          "type": "string",
          "enum": [
            "single",
            "multi",
            "runtime",
            "rulebook"
          ]
        },
        "prompt": {
          "type": "string"
        },
        "stem": {
          "type": "string"
        },
        "options": {
          "type": "array",
          "minItems": 2,
          "maxItems": 8,
          "items": {
            "type": "string"
          }
        },
        "context": {
          "type": [
            "object",
            "string"
          ],
          "additionalProperties": true
        },
        "response_view": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "full"
          ]
        },
        "rulebook": {
          "$ref": "#/$defs/RulebookV1"
        },
        "adapter": {
          "$ref": "#/$defs/TrustedAdapterInvocation"
        }
      },
      "additionalProperties": false
    },
    "RulebookCondition": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "all"
          ],
          "properties": {
            "all": {
              "type": "array",
              "minItems": 1,
              "maxItems": 32,
              "items": {
                "$ref": "#/$defs/RulebookCondition"
              }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "any"
          ],
          "properties": {
            "any": {
              "type": "array",
              "minItems": 1,
              "maxItems": 32,
              "items": {
                "$ref": "#/$defs/RulebookCondition"
              }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "not"
          ],
          "properties": {
            "not": {
              "$ref": "#/$defs/RulebookCondition"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "field",
            "operator"
          ],
          "properties": {
            "field": {
              "type": "string",
              "pattern": "^[A-Za-z_][A-Za-z0-9_.-]{0,159}$"
            },
            "operator": {
              "type": "string",
              "enum": [
                "exists",
                "not_exists",
                "eq",
                "neq",
                "gt",
                "gte",
                "lt",
                "lte",
                "in",
                "not_in",
                "contains",
                "not_contains"
              ]
            },
            "value": {}
          },
          "additionalProperties": false
        }
      ]
    },
    "RulebookInputSchema": {
      "type": "object",
      "properties": {
        "required": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z_][A-Za-z0-9_.-]{0,159}$"
          }
        },
        "properties": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "number",
                  "integer",
                  "boolean",
                  "array",
                  "object",
                  "null"
                ]
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "RulebookOutcome": {
      "type": "object",
      "required": [
        "decision",
        "verdict",
        "action",
        "reason_code"
      ],
      "properties": {
        "decision": {
          "type": "string",
          "enum": [
            "yes",
            "no",
            "review"
          ]
        },
        "verdict": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]{1,79}$"
        },
        "action": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "reason_code": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]{1,79}$"
        }
      },
      "additionalProperties": false
    },
    "RulebookRule": {
      "type": "object",
      "required": [
        "rule_id",
        "condition",
        "outcome"
      ],
      "properties": {
        "rule_id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.:-]{1,119}$"
        },
        "priority": {
          "type": "integer",
          "minimum": -1000,
          "maximum": 1000,
          "default": 0
        },
        "condition": {
          "$ref": "#/$defs/RulebookCondition"
        },
        "outcome": {
          "$ref": "#/$defs/RulebookOutcome"
        }
      },
      "additionalProperties": false
    },
    "RulebookV1": {
      "type": "object",
      "required": [
        "schema_version",
        "rulebook_id",
        "version",
        "rules",
        "default_outcome"
      ],
      "properties": {
        "schema_version": {
          "type": "string",
          "const": "rulebook_v1"
        },
        "rulebook_id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.:-]{1,119}$"
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "input_schema": {
          "$ref": "#/$defs/RulebookInputSchema"
        },
        "rules": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "items": {
            "$ref": "#/$defs/RulebookRule"
          }
        },
        "default_outcome": {
          "$ref": "#/$defs/RulebookOutcome"
        }
      },
      "additionalProperties": false
    },
    "TrustedAdapterInvocation": {
      "type": "object",
      "required": [
        "adapter_id",
        "version",
        "manifest_hash",
        "input"
      ],
      "properties": {
        "adapter_id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.:-]{1,119}$"
        },
        "version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
        },
        "manifest_hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "input": {
          "type": "object",
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    }
  }
}