{
  "$defs": {
    "BpmnNode": {
      "description": "Process node.",
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "$ref": "#/$defs/BpmnNodeKind"
        },
        "label": {
          "type": "string"
        },
        "lane": {
          "description": "Lane the node belongs to.",
          "type": "string"
        },
        "procedure_ref": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef to the SOP / runbook (for tasks)."
        }
      },
      "required": [
        "id",
        "kind",
        "label",
        "lane"
      ],
      "type": "object"
    },
    "BpmnNodeKind": {
      "description": "BPMN node kind.",
      "oneOf": [
        {
          "const": "start_event",
          "description": "Start event.",
          "type": "string"
        },
        {
          "const": "intermediate_event",
          "description": "Intermediate event.",
          "type": "string"
        },
        {
          "const": "end_event",
          "description": "End event.",
          "type": "string"
        },
        {
          "const": "user_task",
          "description": "User task (manual / human).",
          "type": "string"
        },
        {
          "const": "service_task",
          "description": "Service task (system-executed).",
          "type": "string"
        },
        {
          "const": "send_task",
          "description": "Send task (outgoing message).",
          "type": "string"
        },
        {
          "const": "receive_task",
          "description": "Receive task (incoming message).",
          "type": "string"
        },
        {
          "const": "script_task",
          "description": "Script task (engine-executed).",
          "type": "string"
        },
        {
          "const": "manual_task",
          "description": "Manual task.",
          "type": "string"
        },
        {
          "const": "business_rule_task",
          "description": "Business-rule task (decision table).",
          "type": "string"
        },
        {
          "const": "call_activity",
          "description": "Call activity (invokes sub-process).",
          "type": "string"
        },
        {
          "const": "exclusive_gateway",
          "description": "Exclusive (XOR) gateway.",
          "type": "string"
        },
        {
          "const": "inclusive_gateway",
          "description": "Inclusive (OR) gateway.",
          "type": "string"
        },
        {
          "const": "parallel_gateway",
          "description": "Parallel (AND) gateway.",
          "type": "string"
        },
        {
          "const": "event_based_gateway",
          "description": "Event-based gateway.",
          "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"
    },
    "ProcessFlow": {
      "description": "Sequence flow / message flow.",
      "properties": {
        "condition": {
          "description": "Optional condition expression for gateways.",
          "type": [
            "string",
            "null"
          ]
        },
        "from": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "is_message_flow": {
          "description": "Whether this is a message flow (cross-pool).",
          "type": "boolean"
        },
        "to": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "from",
        "to",
        "is_message_flow"
      ],
      "type": "object"
    },
    "ProcessMapStatus": {
      "description": "Process-map lifecycle.",
      "enum": [
        "draft",
        "approved",
        "in_revision",
        "retired"
      ],
      "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"
    },
    "SwimLane": {
      "description": "Swim lane (a participant in the process).",
      "properties": {
        "id": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "role": {
          "$ref": "#/$defs/PathRef",
          "description": "PathRef to the role / team that owns the lane."
        }
      },
      "required": [
        "id",
        "label",
        "role"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/process-map.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Process map.",
  "properties": {
    "bpmn_xml_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the BPMN 2.0 XML artefact."
    },
    "control_basis": {
      "description": "Control basis (ISO 9001 / ITIL etc.).",
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "diagram_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to rendered diagram (SVG / PNG)."
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "flows": {
      "items": {
        "$ref": "#/$defs/ProcessFlow"
      },
      "type": "array"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "lanes": {
      "items": {
        "$ref": "#/$defs/SwimLane"
      },
      "type": "array"
    },
    "last_modeled_on": {
      "$ref": "#/$defs/IsoDate"
    },
    "name": {
      "type": "string"
    },
    "next_review_due": {
      "$ref": "#/$defs/IsoDate"
    },
    "nodes": {
      "items": {
        "$ref": "#/$defs/BpmnNode"
      },
      "type": "array"
    },
    "owner": {
      "$ref": "#/$defs/PathRef"
    },
    "sop_refs": {
      "description": "Cross-references to SOPs implementing this process.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "status": {
      "$ref": "#/$defs/ProcessMapStatus"
    },
    "version": {
      "$ref": "#/$defs/Semver"
    }
  },
  "required": [
    "id",
    "entity",
    "name",
    "description",
    "status",
    "owner",
    "version",
    "lanes",
    "nodes",
    "flows",
    "control_basis",
    "last_modeled_on",
    "next_review_due"
  ],
  "title": "ProcessMap",
  "type": "object",
  "x-corpospec-pillar": "operations"
}