{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/safetibase/ddp-diagrams/schema/ddp-diagram.schema.json",
  "title": "DDP system architecture diagram data (DDP-DIA/1.0)",
  "description": "The input a DDP-STD-001 system architecture diagram is drawn from. Built from the tool selection (system requirements): tools by DDP-CAT-001 id, layer, who provisions them, connections and what flows along them, CDE states and parties.",
  "type": "object",
  "required": ["schema", "project", "drawing", "revisions", "parties", "cde", "tools", "connections"],
  "additionalProperties": false,
  "properties": {
    "schema": { "const": "DDP-DIA/1.0" },
    "project": {
      "type": "object",
      "required": ["id", "name", "description", "rung", "jurisdiction", "synthetic"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "description": "Test project or project code, e.g. TP-L2" },
        "name": { "type": "string" },
        "description": { "type": "string", "description": "One line: the appointment type, e.g. 'Multidisciplinary design appointment'" },
        "rung": { "enum": ["L1", "L2", "L3", "L4"] },
        "jurisdiction": { "type": "string", "description": "As set in the requirements digest, e.g. 'North America (NBIMS-US V4)', 'ISO 19650', 'Canada (CAN/CGSB/CSA-ISO 19650)'" },
        "synthetic": { "type": "boolean" }
      }
    },
    "drawing": {
      "type": "object",
      "required": ["number", "title", "revision", "status", "date", "drawn_by", "sheet", "scale"],
      "additionalProperties": false,
      "properties": {
        "number": { "type": "string" },
        "title": { "type": "string" },
        "revision": { "type": "string", "pattern": "^[PC][0-9]{2}$" },
        "status": { "type": "string", "description": "Suitability code and description, e.g. 'S2 For information'" },
        "date": { "type": "string", "format": "date" },
        "drawn_by": { "type": "string" },
        "checked_by": { "type": "string" },
        "sheet": { "const": "A3 landscape" },
        "scale": { "const": "NTS" }
      }
    },
    "revisions": {
      "type": "array", "minItems": 1,
      "description": "Accumulates; never rewritten. The last entry must match drawing.revision.",
      "items": {
        "type": "object", "required": ["rev", "date", "description", "by"], "additionalProperties": false,
        "properties": { "rev": { "type": "string", "pattern": "^[PC][0-9]{2}$" }, "date": { "type": "string", "format": "date" }, "description": { "type": "string" }, "by": { "type": "string" }, "checked": { "type": "string" } }
      }
    },
    "parties": {
      "type": "array", "minItems": 1, "maxItems": 8,
      "items": { "type": "object", "required": ["id", "name", "role"], "additionalProperties": false,
        "properties": { "id": { "type": "string", "pattern": "^[A-Z0-9]{2,5}$" }, "name": { "type": "string" }, "role": { "type": "string" } } }
    },
    "cde": {
      "type": "object", "required": ["primary", "states"], "additionalProperties": false,
      "properties": {
        "primary": { "type": "string", "pattern": "^TC-[0-9]{3}$", "description": "The tool that holds the ISO 19650 container states; drawn as the hero card" },
        "states": {
          "type": "array", "minItems": 4, "maxItems": 4,
          "items": { "type": "object", "required": ["id", "label", "codes", "access"], "additionalProperties": false,
            "properties": { "id": { "enum": ["WIP", "SHARED", "PUBLISHED", "ARCHIVED"] }, "label": { "type": "string" }, "short": { "type": "string" }, "codes": { "type": "string" }, "access": { "type": "array", "items": { "type": "string" } } } }
        }
      }
    },
    "tools": {
      "type": "array", "minItems": 2, "maxItems": 40,
      "items": {
        "type": "object",
        "required": ["tc", "label", "vendor", "layer", "choice_group", "provisioned_by", "parties", "role"],
        "additionalProperties": false,
        "properties": {
          "tc": { "type": "string", "pattern": "^TC-[0-9]{3}$" },
          "label": { "type": "string", "description": "Name shown on the tile" },
          "short": { "type": "string", "description": "Short name for chips and schedules, e.g. ACC" },
          "mono": { "type": "string", "maxLength": 3, "description": "Monogram used only when no official logo is filed" },
          "vendor": { "type": "string" },
          "layer": { "enum": ["authoring", "coordination", "intelligence", "consumption"] },
          "choice_group": { "type": "string" },
          "provisioned_by": { "enum": ["Our IT", "Client", "Contractor"], "description": "Resolved at tool selection; catalogue combinations ('Our IT or client') must be resolved to one" },
          "parties": { "type": "array", "items": { "type": "string" } },
          "role": { "type": "string", "description": "One line on what it does on this project" },
          "hosted_on": { "type": "string", "pattern": "^TC-[0-9]{3}$" },
          "logo": { "type": "string", "description": "Optional override; normally filled from logos/index.json at render time" }
        }
      }
    },
    "connections": {
      "type": "array",
      "items": {
        "type": "object", "required": ["id", "from", "to", "flow", "formats", "type", "direction"], "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "pattern": "^F[0-9]{2,3}$" },
          "from": { "type": "string", "pattern": "^TC-[0-9]{3}$" },
          "to": { "type": "string", "pattern": "^TC-[0-9]{3}$" },
          "flow": { "type": "string", "maxLength": 32, "description": "What flows, in the delivery team's words" },
          "formats": { "type": "array", "minItems": 1, "items": { "type": "string" } },
          "type": { "enum": ["container", "sync", "direct", "view"], "description": "container: managed exchange through CDE states; sync: automated connector or API; direct: file exchange outside the CDE; view: view or stream only" },
          "direction": { "enum": ["one", "both"] }
        }
      }
    },
    "notes": { "type": "array", "items": { "type": "string" } }
  }
}
