{
  "$defs": {
    "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"
    },
    "RaciAssignment": {
      "description": "One RACI assignment for a step.",
      "properties": {
        "raci": {
          "$ref": "#/$defs/RaciRole"
        },
        "role": {
          "$ref": "#/$defs/PathRef",
          "description": "PathRef to the role (people/roles/) — not the individual person."
        }
      },
      "required": [
        "role",
        "raci"
      ],
      "type": "object"
    },
    "RaciRole": {
      "description": "RACI role.",
      "oneOf": [
        {
          "const": "responsible",
          "description": "Responsible — does the work.",
          "type": "string"
        },
        {
          "const": "accountable",
          "description": "Accountable — owns the outcome (single per task).",
          "type": "string"
        },
        {
          "const": "consulted",
          "description": "Consulted.",
          "type": "string"
        },
        {
          "const": "informed",
          "description": "Informed.",
          "type": "string"
        }
      ]
    },
    "Semver": {
      "description": "Semantic version string (MAJOR.MINOR.PATCH).",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$",
      "type": "string"
    },
    "SopCategory": {
      "description": "SOP category.",
      "oneOf": [
        {
          "enum": [
            "other"
          ],
          "type": "string"
        },
        {
          "const": "information_security",
          "description": "Information security / access control.",
          "type": "string"
        },
        {
          "const": "financial",
          "description": "Financial close / accounting.",
          "type": "string"
        },
        {
          "const": "human_resources",
          "description": "Hiring / onboarding / termination.",
          "type": "string"
        },
        {
          "const": "customer_ops",
          "description": "Customer onboarding / service.",
          "type": "string"
        },
        {
          "const": "engineering_release",
          "description": "Engineering release / change-management.",
          "type": "string"
        },
        {
          "const": "procurement",
          "description": "Procurement / vendor onboarding.",
          "type": "string"
        },
        {
          "const": "legal",
          "description": "Legal / contracts.",
          "type": "string"
        },
        {
          "const": "privacy",
          "description": "Data-subject-rights operations.",
          "type": "string"
        },
        {
          "const": "incident_response",
          "description": "Incident response / postmortem.",
          "type": "string"
        },
        {
          "const": "business_continuity",
          "description": "Business-continuity / disaster recovery.",
          "type": "string"
        },
        {
          "const": "quality",
          "description": "Quality assurance / product.",
          "type": "string"
        }
      ]
    },
    "SopStatus": {
      "description": "Lifecycle.",
      "enum": [
        "draft",
        "approved",
        "in_revision",
        "retired"
      ],
      "type": "string"
    },
    "SopStep": {
      "description": "One SOP step.",
      "properties": {
        "acceptance_criterion": {
          "description": "Expected output / acceptance criterion.",
          "type": "string"
        },
        "action": {
          "type": "string"
        },
        "assignments": {
          "items": {
            "$ref": "#/$defs/RaciAssignment"
          },
          "type": "array"
        },
        "ordinal": {
          "description": "Step ordinal.",
          "format": "int32",
          "type": "integer"
        },
        "sla_duration": {
          "description": "Maximum time the step should take (ISO 8601 duration).",
          "type": [
            "string",
            "null"
          ]
        },
        "tool_refs": {
          "description": "PathRef to tooling / template artefacts.",
          "items": {
            "$ref": "#/$defs/PathRef"
          },
          "type": "array"
        }
      },
      "required": [
        "ordinal",
        "action",
        "acceptance_criterion",
        "assignments"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/sop.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "SOP record.",
  "properties": {
    "artefact_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the doc artefact (Notion, wiki, PDF)."
    },
    "category": {
      "$ref": "#/$defs/SopCategory"
    },
    "control_basis": {
      "description": "Control basis citations (ISO clause, SOC criterion).",
      "type": "string"
    },
    "effective_from": {
      "$ref": "#/$defs/IsoDate"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "name": {
      "type": "string"
    },
    "next_review_due": {
      "$ref": "#/$defs/IsoDate"
    },
    "objective": {
      "type": "string"
    },
    "owner": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to the process owner (single accountable)."
    },
    "postconditions": {
      "description": "Post-conditions / outputs.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "preconditions": {
      "description": "Pre-conditions / inputs.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "review_cadence": {
      "description": "Review cadence (e.g. \"P12M\" — annual).",
      "type": "string"
    },
    "status": {
      "$ref": "#/$defs/SopStatus"
    },
    "steps": {
      "description": "Steps (strictly ascending ordinals).",
      "items": {
        "$ref": "#/$defs/SopStep"
      },
      "type": "array"
    },
    "triggers": {
      "description": "Trigger conditions (\"when does this SOP run?\").",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "version": {
      "$ref": "#/$defs/Semver",
      "description": "Versioned (e.g. \"1.2.0\")."
    }
  },
  "required": [
    "id",
    "entity",
    "category",
    "name",
    "version",
    "objective",
    "triggers",
    "preconditions",
    "steps",
    "postconditions",
    "control_basis",
    "owner",
    "status",
    "effective_from",
    "review_cadence",
    "next_review_due"
  ],
  "title": "StandardOperatingProcedure",
  "type": "object",
  "x-corpospec-pillar": "operations"
}