{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.deixei.com/aes/v0.1.0/cab_change.json",
  "title": "CAB Change File",
  "description": "Input artefact submitted to `ops cab evaluate`. Describes a proposed change with the structured context the CAB needs to render a go/no-go decision.",

  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "change_id",
    "change_type",
    "submitter",
    "summary",
    "description",
    "target",
    "risk",
    "customer_impact",
    "rollback",
    "test_evidence",
    "monitoring",
    "security_compliance",
    "approvers_required",
    "policy_template",
    "policy_template_version"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "change_id": {
      "type": "string",
      "minLength": 1
    },
    "change_type": {
      "type": "string",
      "enum": ["app_deploy", "infra_change", "data_migration", "emergency_fix", "config_change", "other"]
    },
    "submitter": {
      "type": "object",
      "additionalProperties": false,
      "required": ["team", "submitted_at"],
      "oneOf": [
        { "required": ["user_upn"] },
        { "required": ["agent_id"] }
      ],
      "properties": {
        "user_upn":     { "type": "string", "minLength": 1 },
        "agent_id":     { "type": "string", "minLength": 1 },
        "team":         { "type": "string", "minLength": 1 },
        "submitted_at": { "type": "string", "format": "date-time" }
      }
    },
    "summary":     { "type": "string", "minLength": 1 },
    "description": { "type": "string", "minLength": 1 },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["environment", "systems"],
      "properties": {
        "environment": { "type": "string", "minLength": 1 },
        "systems":     { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "regions":     { "type": "array", "items": { "type": "string" } }
      }
    },
    "risk": {
      "type": "object",
      "additionalProperties": false,
      "required": ["level", "rationale"],
      "properties": {
        "level":     { "type": "string", "enum": ["low", "medium", "high", "critical"] },
        "rationale": { "type": "string", "minLength": 1 }
      }
    },
    "customer_impact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["expected", "description"],
      "properties": {
        "expected":     { "type": "boolean" },
        "description":  { "type": "string", "minLength": 1 },
        "blast_radius": { "type": "string" }
      }
    },
    "rollback": {
      "type": "object",
      "additionalProperties": false,
      "required": ["plan_description"],
      "properties": {
        "plan_description": { "type": "string", "minLength": 1 },
        "command_ref":      { "type": "string" }
      }
    },
    "test_evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["type", "ref", "result"],
        "properties": {
          "type":   { "type": "string", "enum": ["test_run", "scan", "review", "other"] },
          "ref":    { "type": "string", "minLength": 1 },
          "result": { "type": "string", "enum": ["pass", "fail", "n/a"] }
        }
      }
    },
    "monitoring": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dashboards", "alerts", "post_change_check_window"],
      "properties": {
        "dashboards":               { "type": "array", "items": { "type": "string" } },
        "alerts":                   { "type": "array", "items": { "type": "string" } },
        "post_change_check_window": { "type": "string", "description": "ISO 8601 duration." }
      }
    },
    "security_compliance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["impact", "description", "chk_guidance_refs"],
      "properties": {
        "impact":            { "type": "boolean" },
        "description":       { "type": "string", "minLength": 1 },
        "chk_guidance_refs": { "type": "array", "items": { "type": "string" } }
      }
    },
    "approvers_required": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["role"],
        "properties": {
          "role":         { "type": "string", "minLength": 1 },
          "specific_upn": { "type": "string" }
        }
      }
    },
    "target_window": {
      "type": "object",
      "additionalProperties": false,
      "required": ["start", "end"],
      "properties": {
        "start": { "type": "string", "format": "date-time" },
        "end":   { "type": "string", "format": "date-time" }
      }
    },
    "policy_template":         { "type": "string", "minLength": 1 },
    "policy_template_version": { "type": "string", "minLength": 1 }
  }
}
