{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aruntime.com/schemas/policy-approval.v1.schema.json",
  "title": "ARuntime Policy and Approval Decision v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contractVersion",
    "policyId",
    "policyVersion",
    "decisionId",
    "scope",
    "inputs",
    "decision",
    "reasonCodes",
    "requiredApprovals",
    "approvalAuthority",
    "issuedUtc",
    "expiresUtc",
    "overridePolicy",
    "evidence",
    "redaction",
    "reviewPath"
  ],
  "properties": {
    "contractVersion": {
      "const": "aruntime.policy-approval.v1"
    },
    "policyId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "policyVersion": {
      "type": "string",
      "minLength": 1
    },
    "decisionId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "taskTypes",
        "tenantRefs"
      ],
      "properties": {
        "taskTypes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tenantRefs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "toolRefs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "inputs": {
      "type": "object",
      "description": "Minimized policy input values or references.",
      "additionalProperties": true
    },
    "decision": {
      "enum": [
        "allow",
        "deny",
        "approval-required",
        "abstain"
      ]
    },
    "reasonCodes": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 160,
        "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
      }
    },
    "requiredApprovals": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "role",
          "count"
        ],
        "properties": {
          "role": {
            "type": "string"
          },
          "count": {
            "type": "integer",
            "minimum": 1
          },
          "separationOfDuties": {
            "type": "boolean"
          }
        }
      }
    },
    "approvalAuthority": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "issuedUtc": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$",
      "description": "UTC ISO 8601 timestamp ending in Z."
    },
    "expiresUtc": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$",
          "description": "UTC ISO 8601 timestamp ending in Z."
        },
        {
          "type": "null"
        }
      ]
    },
    "overridePolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowed",
        "authorityRefs"
      ],
      "properties": {
        "allowed": {
          "type": "boolean"
        },
        "authorityRefs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "requiresReason": {
          "type": "boolean"
        }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "recordDecision",
        "requiredFields"
      ],
      "properties": {
        "recordDecision": {
          "type": "boolean"
        },
        "requiredFields": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "redaction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "rules"
      ],
      "properties": {
        "rules": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "reviewPath": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "available",
        "destination"
      ],
      "properties": {
        "available": {
          "type": "boolean"
        },
        "destination": {
          "type": [
            "string",
            "null"
          ]
        },
        "slaSeconds": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        }
      }
    }
  }
}
