{
  "$defs": {
    "ChangeApproval": {
      "description": "Approval record.",
      "properties": {
        "approved": {
          "description": "Whether the approver approved.",
          "type": "boolean"
        },
        "approver": {
          "$ref": "#/$defs/PathRef"
        },
        "decision_at": {
          "$ref": "#/$defs/IsoDate"
        },
        "note": {
          "description": "Free-form note.",
          "type": [
            "string",
            "null"
          ]
        },
        "role": {
          "description": "Approver role (e.g. \"engineering_manager\", \"cab_chair\", \"cto\").",
          "type": "string"
        }
      },
      "required": [
        "approver",
        "role",
        "decision_at",
        "approved"
      ],
      "type": "object"
    },
    "ChangeCategory": {
      "description": "Change category.",
      "oneOf": [
        {
          "const": "code_deployment",
          "description": "Code deployment.",
          "type": "string"
        },
        {
          "const": "infrastructure",
          "description": "Infrastructure change.",
          "type": "string"
        },
        {
          "const": "configuration",
          "description": "Configuration change.",
          "type": "string"
        },
        {
          "const": "schema_migration",
          "description": "Database schema migration.",
          "type": "string"
        },
        {
          "const": "access",
          "description": "Access / permission change.",
          "type": "string"
        },
        {
          "const": "security_policy",
          "description": "Security policy.",
          "type": "string"
        },
        {
          "const": "vendor",
          "description": "Vendor change.",
          "type": "string"
        },
        {
          "const": "process",
          "description": "Process change.",
          "type": "string"
        },
        {
          "const": "documentation",
          "description": "Documentation only.",
          "type": "string"
        }
      ]
    },
    "ChangeClass": {
      "description": "Change class.",
      "oneOf": [
        {
          "const": "standard",
          "description": "Pre-approved (no CAB required).",
          "type": "string"
        },
        {
          "const": "normal",
          "description": "CAB-approved (normal change).",
          "type": "string"
        },
        {
          "const": "emergency",
          "description": "Emergency (post-hoc approval).",
          "type": "string"
        },
        {
          "const": "major",
          "description": "Major (architectural — requires BDR).",
          "type": "string"
        }
      ]
    },
    "ChangeRisk": {
      "description": "Risk level.",
      "enum": [
        "low",
        "medium",
        "high",
        "critical"
      ],
      "type": "string"
    },
    "ChangeStatus": {
      "description": "Lifecycle.",
      "oneOf": [
        {
          "const": "draft",
          "description": "Drafted, not yet submitted.",
          "type": "string"
        },
        {
          "const": "submitted",
          "description": "Submitted, awaiting CAB review.",
          "type": "string"
        },
        {
          "const": "approved",
          "description": "Approved.",
          "type": "string"
        },
        {
          "const": "rejected",
          "description": "Rejected (with reason).",
          "type": "string"
        },
        {
          "const": "implementing",
          "description": "Implementation in progress.",
          "type": "string"
        },
        {
          "const": "implemented",
          "description": "Implemented, awaiting verification.",
          "type": "string"
        },
        {
          "const": "verified",
          "description": "Verified — change applied successfully.",
          "type": "string"
        },
        {
          "const": "rolled_back",
          "description": "Rolled back.",
          "type": "string"
        },
        {
          "const": "completed",
          "description": "Completed (with PIR).",
          "type": "string"
        }
      ]
    },
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "PathRef": {
      "description": "Path-based cross-reference relative to .corpospec/ root.\nPattern: `^[a-z0-9_-]+(/[a-z0-9_.-]+)+$`",
      "pattern": "^[a-z0-9_-]+(/[a-z0-9_.-]+)+$",
      "type": "string"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/change-request.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Change-request record.",
  "properties": {
    "affected_systems": {
      "description": "Systems affected.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "approvals": {
      "description": "Approvals received.",
      "items": {
        "$ref": "#/$defs/ChangeApproval"
      },
      "type": "array"
    },
    "bdr_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the BDR (for Major class)."
    },
    "category": {
      "$ref": "#/$defs/ChangeCategory"
    },
    "class": {
      "$ref": "#/$defs/ChangeClass"
    },
    "created_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "description": {
      "type": "string"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "impact_assessment": {
      "description": "Impact-assessment narrative.",
      "type": "string"
    },
    "implemented_at": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    },
    "implementer": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to the implementer."
    },
    "justification": {
      "type": "string"
    },
    "pir_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the post-implementation review (PIR)."
    },
    "requestor": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to the requestor."
    },
    "risk": {
      "$ref": "#/$defs/ChangeRisk"
    },
    "rollback_plan": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "Rollback plan (PathRef to runbook)."
    },
    "scheduled_for": {
      "$ref": "#/$defs/IsoDate",
      "description": "Scheduled implementation window."
    },
    "status": {
      "$ref": "#/$defs/ChangeStatus"
    },
    "title": {
      "type": "string"
    },
    "triggering_incident": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to incident triggered (for emergency changes)."
    },
    "verified_at": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "entity",
    "class",
    "category",
    "status",
    "risk",
    "title",
    "description",
    "justification",
    "requestor",
    "implementer",
    "affected_systems",
    "impact_assessment",
    "approvals",
    "scheduled_for",
    "created_at"
  ],
  "title": "ChangeRequest",
  "type": "object",
  "x-corpospec-pillar": "operations"
}