{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:musyg:ai-adoption-playbook:project-dossier-schema:0.3.0",
  "title": "AI Adoption Playbook local project dossier",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "playbook_version",
    "dossier_id",
    "created_at",
    "updated_at",
    "language",
    "status",
    "boundary",
    "context",
    "active_phase",
    "fields",
    "conditioned_controls",
    "matched_control_ids",
    "completed_phases",
    "artifacts",
    "change_review"
  ],
  "properties": {
    "schema_version": { "const": "0.3.0" },
    "playbook_version": { "const": "0.2.2" },
    "dossier_id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{7,127}$" },
    "created_at": { "type": "string", "format": "date-time" },
    "updated_at": { "type": "string", "format": "date-time" },
    "language": { "enum": ["en", "fr"] },
    "status": { "const": "working_draft" },
    "boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["local_only", "no_raw_evidence", "not_certification"],
      "properties": {
        "local_only": { "const": true },
        "no_raw_evidence": { "const": true },
        "not_certification": { "const": true }
      }
    },
    "context": {
      "type": "object",
      "additionalProperties": false,
      "required": ["organization_type", "use_pattern", "jurisdiction", "integration_level", "autonomy_level", "risk_level"],
      "properties": {
        "organization_type": { "enum": ["independent", "tpe", "pme", "nonprofit", "public"] },
        "use_pattern": { "enum": ["generation", "retrieval", "classification", "prediction", "conversation", "multimodal", "agentic"] },
        "jurisdiction": { "enum": ["CH", "EU", "BOTH"] },
        "integration_level": { "enum": ["copilot", "agent", "agency"] },
        "autonomy_level": { "type": "integer", "minimum": 0, "maximum": 4 },
        "risk_level": { "type": "integer", "minimum": 0, "maximum": 3 }
      }
    },
    "active_phase": { "type": "integer", "minimum": 0, "maximum": 11 },
    "fields": { "type": "object", "additionalProperties": { "type": "string" } },
    "conditioned_controls": { "type": "object", "additionalProperties": { "type": "boolean" } },
    "matched_control_ids": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
    "completed_phases": { "type": "array", "uniqueItems": true, "items": { "type": "integer", "minimum": 0, "maximum": 11 } },
    "artifacts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["system_register", "risk_assessment", "evaluation_plan", "implementation_checklist"],
      "properties": {
        "system_register": { "$ref": "#/$defs/fieldArtifact" },
        "risk_assessment": { "$ref": "#/$defs/fieldArtifact" },
        "evaluation_plan": { "$ref": "#/$defs/fieldArtifact" },
        "implementation_checklist": {
          "type": "object",
          "additionalProperties": false,
          "required": ["items"],
          "properties": {
            "items": {
              "type": "object",
              "additionalProperties": { "$ref": "#/$defs/checklistItem" }
            }
          }
        }
      }
    },
    "change_review": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["baseline", "compared_at", "items"],
          "properties": {
            "baseline": {
              "type": "object",
              "additionalProperties": false,
              "required": ["dossier_id", "updated_at", "schema_version", "playbook_version", "snapshot"],
              "properties": {
                "dossier_id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{7,127}$" },
                "updated_at": { "type": "string", "format": "date-time" },
                "schema_version": { "enum": ["0.1.0", "0.2.0", "0.3.0"] },
                "playbook_version": { "const": "0.2.2" },
                "snapshot": { "$ref": "#/$defs/projectSnapshot" }
              }
            },
            "compared_at": { "type": "string", "format": "date-time" },
            "items": {
              "type": "object",
              "additionalProperties": { "$ref": "#/$defs/changeReviewItem" }
            }
          }
        }
      ]
    }
  },
  "$defs": {
    "projectSnapshot": {
      "type": "object",
      "additionalProperties": false,
      "required": ["context", "fields", "conditioned_controls", "matched_control_ids", "completed_phases", "artifacts"],
      "properties": {
        "context": { "$ref": "#/properties/context" },
        "fields": { "$ref": "#/properties/fields" },
        "conditioned_controls": { "$ref": "#/properties/conditioned_controls" },
        "matched_control_ids": { "$ref": "#/properties/matched_control_ids" },
        "completed_phases": { "$ref": "#/properties/completed_phases" },
        "artifacts": { "$ref": "#/properties/artifacts" }
      }
    },
    "changeReviewItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "domain", "before", "after", "recommended_action", "decision", "owner", "due_date", "evidence_ref", "note"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "domain": { "enum": ["scope", "risk", "architecture", "evaluation", "controls", "ownership", "delivery"] },
        "before": { "type": "string" },
        "after": { "type": "string" },
        "recommended_action": { "enum": ["review", "reassess", "restart"] },
        "decision": { "enum": ["pending", "accepted", "reassess", "restart"] },
        "owner": { "type": "string" },
        "due_date": { "type": "string" },
        "evidence_ref": { "type": "string" },
        "note": { "type": "string" }
      }
    },
    "fieldArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["fields"],
      "properties": {
        "fields": {
          "type": "object",
          "additionalProperties": { "$ref": "#/$defs/artifactField" }
        }
      }
    },
    "artifactField": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "mode"],
      "properties": {
        "value": { "type": "string" },
        "mode": { "enum": ["linked", "manual"] }
      }
    },
    "checklistItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "status_mode", "owner", "due_date", "evidence_ref"],
      "properties": {
        "status": { "enum": ["not_started", "in_progress", "done", "not_applicable"] },
        "status_mode": { "enum": ["linked", "manual"] },
        "owner": { "type": "string" },
        "due_date": { "type": "string" },
        "evidence_ref": { "type": "string" }
      }
    }
  }
}
