{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cyber-essentials.standards.sovereignweb.site/data/model/unit.schema.json",
  "title": "Cyber Essentials unit (fractal model v1)",
  "description": "One unit of an organisation: a team, a division, a client environment, an MSP's corporate IT or an MSP's service-delivery estate. A unit holds its own scope and evidence. Units nest by 'parent' and aggregate upwards. Independent tool, not certification.",
  "type": "object",
  "required": ["contract_version", "id", "name", "kind", "scope", "controls"],
  "properties": {
    "contract_version": { "const": "cyber-essentials.cell/unit/v1" },
    "id": { "type": "string", "pattern": "^[a-z0-9-]+(/[a-z0-9-]+)*$", "description": "Path-style id. The parent's id is a prefix: org/division/team." },
    "name": { "type": "string" },
    "kind": { "enum": ["organisation", "division", "team", "site", "shared-service", "client-environment", "msp-corporate", "msp-delivery", "excluded"] },
    "parent": { "type": ["string", "null"] },
    "owner_role": { "type": "string", "description": "A role, never a private person's name." },
    "scope": {
      "type": "object",
      "required": ["status"],
      "properties": {
        "status": { "enum": ["in-scope", "sub-set", "out-of-scope"], "description": "in-scope: inside the applicant's certificate scope. sub-set: a separated part assessed on its own. out-of-scope: excluded, with a reason and a separation." },
        "certificate_scope": { "type": ["string", "null"], "description": "Which certificate (by local id) this unit's scope falls under, or null." },
        "boundary": { "type": "string", "description": "Plain words: what is inside this unit." },
        "separation": { "type": ["string", "null"], "description": "For a sub-set or exclusion: how it is separated (for example a firewall or VLAN that blocks traffic)." },
        "reason": { "type": ["string", "null"] },
        "assets": {
          "type": "object",
          "properties": {
            "end_user_devices": { "type": "array", "items": { "$ref": "#/$defs/device" } },
            "servers": { "type": "array", "items": { "$ref": "#/$defs/device" } },
            "network_devices": { "type": "array", "items": { "$ref": "#/$defs/device" } },
            "cloud_services": { "type": "array", "items": { "$ref": "#/$defs/cloud" } }
          }
        },
        "accounts": {
          "type": "object",
          "properties": {
            "users": { "type": "integer" },
            "administrators": { "type": "integer" },
            "third_party_accounts": { "type": "integer" }
          }
        },
        "home_workers": { "type": "integer" },
        "byod": { "type": "boolean" }
      }
    },
    "controls": {
      "type": "object",
      "description": "Keyed by control id. A control may be held by this unit or inherited from another unit (for example a shared IT platform).",
      "propertyNames": { "enum": ["firewalls", "secure-configuration", "security-update-management", "user-access-control", "malware-protection"] },
      "additionalProperties": { "$ref": "#/$defs/control" }
    },
    "delivers_to": { "type": "array", "items": { "type": "string" }, "description": "For msp-delivery or shared-service units: the unit ids this unit operates or can reach." },
    "certification": {
      "type": "object",
      "properties": {
        "ce": { "$ref": "#/$defs/cert" },
        "ce_plus": { "$ref": "#/$defs/cert" }
      }
    },
    "synthetic": { "type": "boolean", "description": "True for worked examples. Real forks set false." }
  },
  "$defs": {
    "device": {
      "type": "object",
      "required": ["kind", "count"],
      "properties": {
        "kind": { "type": "string" },
        "os": { "type": "string" },
        "count": { "type": "integer" },
        "licensed_and_supported": { "type": "boolean" },
        "managed_by": { "type": ["string", "null"], "description": "Unit id that manages it, when not this unit." }
      }
    },
    "cloud": {
      "type": "object",
      "required": ["name", "model"],
      "properties": {
        "name": { "type": "string" },
        "model": { "enum": ["IaaS", "PaaS", "SaaS"] },
        "admin_mfa": { "type": "boolean" },
        "user_mfa": { "type": "boolean" }
      }
    },
    "control": {
      "type": "object",
      "required": ["status"],
      "properties": {
        "status": { "enum": ["met", "partial", "not-met", "unknown", "not-applicable"] },
        "inherits_from": { "type": ["string", "null"], "description": "Unit id that provides this control. The aggregate takes that unit's status." },
        "answers": { "type": "object", "description": "Keyed by question id from data/standard/questions.public.json." },
        "findings": { "type": "array", "items": { "type": "string" } },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } }
      }
    },
    "evidence": {
      "type": "object",
      "required": ["id", "title", "collected_on"],
      "properties": {
        "id": { "type": "string" },
        "title": { "type": "string" },
        "kind": { "enum": ["screenshot", "export", "policy", "config", "scan", "attestation", "ticket", "other"] },
        "location": { "type": "string", "description": "Where the evidence lives in the owner's own fork or vault. Never in this public repository." },
        "collected_on": { "type": "string", "format": "date" },
        "review_by": { "type": "string", "format": "date" },
        "requirement_refs": { "type": "array", "items": { "type": "string" } },
        "verified_by": { "enum": ["owner", "agent-with-consent", "assessor", "none"] },
        "consent_ref": { "type": ["string", "null"], "description": "Id of the consent record that let an agent read or write this, see docs/agent-consent.md." }
      }
    },
    "cert": {
      "type": "object",
      "properties": {
        "id": { "type": "string", "description": "Local id, for example cert-corp-2026." },
        "certificate_number": { "type": ["string", "null"] },
        "scope_statement": { "type": ["string", "null"], "description": "The scope wording as it appears on the certificate." },
        "issued_on": { "type": ["string", "null"], "format": "date" },
        "expires_on": { "type": ["string", "null"], "format": "date" }
      }
    }
  }
}
