{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nsta1.github.io/Orleans.Lattice/docs/agents/schemas/governance-authorization.schema.json",
  "schema": "lattice.agents/json-schema/v1",
  "title": "Orleans.Lattice authorization decision trees",
  "description": "Authorization decision trees. The first node of each tree is its root; node order is semantic. Every on_true and on_false names a node id or a terminal id of the same tree.",
  "type": "object",
  "required": [
    "schema",
    "decision_trees"
  ],
  "properties": {
    "schema": {
      "const": "lattice.agents/governance-authorization/v1"
    },
    "decision_trees": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "nodes",
          "terminals",
          "fail_closed",
          "sources"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "nodes": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "check",
                "on_true",
                "on_false",
                "source"
              ],
              "properties": {
                "id": {
                  "$ref": "#/$defs/id"
                },
                "check": {
                  "type": "string",
                  "minLength": 1
                },
                "on_true": {
                  "$ref": "#/$defs/id"
                },
                "on_false": {
                  "$ref": "#/$defs/id"
                },
                "source": {
                  "$ref": "#/$defs/source"
                }
              },
              "additionalProperties": false
            },
            "minItems": 1
          },
          "terminals": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "outcome"
              ],
              "properties": {
                "id": {
                  "$ref": "#/$defs/id"
                },
                "outcome": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "additionalProperties": false
            },
            "minItems": 1
          },
          "fail_closed": {
            "type": "string",
            "minLength": 1
          },
          "sources": {
            "$ref": "#/$defs/sources"
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    }
  },
  "additionalProperties": false,
  "$defs": {
    "claim": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "statement",
            "source"
          ],
          "properties": {
            "statement": {
              "type": "string",
              "minLength": 1
            },
            "source": {
              "$ref": "#/$defs/source"
            }
          },
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/uncertain"
        }
      ]
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "package": {
      "type": "string",
      "pattern": "^Orleans\\.Lattice(\\.[A-Z][A-Za-z0-9]*)*$"
    },
    "packages": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^Orleans\\.Lattice(\\.[A-Z][A-Za-z0-9]*)*$"
      }
    },
    "source": {
      "type": "string",
      "pattern": "^((src|docs|test|samples|spec|tools|benchmark|reference-architecture|\\.github)/[A-Za-z0-9_./\\-]+|FEATURES\\.md|PACKAGES\\.md|README\\.md|reference-architecture\\.md)(#[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)?$"
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^((src|docs|test|samples|spec|tools|benchmark|reference-architecture|\\.github)/[A-Za-z0-9_./\\-]+|FEATURES\\.md|PACKAGES\\.md|README\\.md|reference-architecture\\.md)(#[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)?$"
      }
    },
    "text": {
      "type": "string",
      "minLength": 1
    },
    "uncertain": {
      "type": "object",
      "required": [
        "status",
        "reason",
        "required_source"
      ],
      "properties": {
        "status": {
          "const": "uncertain"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "required_source": {
          "type": "string",
          "minLength": 1
        },
        "issue": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    }
  }
}
