{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rodgui.github.io/ai-agent-governance-framework/schemas/enterprise-tool-registry.schema.json",
  "title": "Enterprise Tool Registry",
  "description": "Tools autorizadas com versão, owner, capabilities, limites, gateways e mecanismos de contenção.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "catalogVersion",
    "title",
    "owner",
    "lastReviewed",
    "entries"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.0"
    },
    "catalogVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?$"
    },
    "title": {
      "type": "string",
      "minLength": 3
    },
    "owner": {
      "type": "string",
      "minLength": 3
    },
    "lastReviewed": {
      "type": "string",
      "format": "date"
    },
    "entries": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/entry"
      }
    }
  },
  "$defs": {
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "version",
        "owner",
        "protocol",
        "class",
        "stateChanging",
        "reversible",
        "approvalModes",
        "status",
        "gatewayRef",
        "killSwitchRef",
        "allowedRiskTiers",
        "allowedScopes",
        "provenance",
        "reviewExpiresAt"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^TLR-[A-Z0-9-]{3,80}$"
        },
        "name": {
          "type": "string",
          "minLength": 3
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "owner": {
          "type": "string",
          "minLength": 3
        },
        "protocol": {
          "enum": [
            "api",
            "mcp",
            "browser",
            "code",
            "queue",
            "other"
          ]
        },
        "class": {
          "enum": [
            "observe",
            "create",
            "modify",
            "execute",
            "approve",
            "delete",
            "delegate"
          ]
        },
        "stateChanging": {
          "type": "boolean"
        },
        "reversible": {
          "type": "boolean"
        },
        "approvalModes": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "automated",
              "human",
              "dual-control",
              "prohibited"
            ]
          }
        },
        "status": {
          "enum": [
            "approved",
            "conditional",
            "deprecated",
            "blocked"
          ]
        },
        "gatewayRef": {
          "type": "string",
          "minLength": 3
        },
        "killSwitchRef": {
          "type": "string",
          "minLength": 3
        },
        "allowedRiskTiers": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "T1",
              "T2",
              "T3",
              "T4"
            ]
          }
        },
        "allowedScopes": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "provenance": {
          "type": "string",
          "minLength": 3
        },
        "conditionRefs": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 3
          }
        },
        "reviewExpiresAt": {
          "type": "string",
          "format": "date"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "conditional"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "required": [
              "conditionRefs"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "class": {
                "const": "observe"
              }
            },
            "required": [
              "class"
            ]
          },
          "then": {
            "properties": {
              "stateChanging": {
                "const": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "class": {
                "enum": [
                  "create",
                  "modify",
                  "execute",
                  "approve",
                  "delete",
                  "delegate"
                ]
              }
            },
            "required": [
              "class"
            ]
          },
          "then": {
            "properties": {
              "stateChanging": {
                "const": true
              }
            }
          }
        }
      ]
    }
  }
}
