{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://oto-enterprise-os-dtp/devops/deploy.schema.json",
  "title": "Run-book de déploiement VPS unifié (agrégat de tous les livrables gated)",
  "description": "Contrat de sortie de deploy_runbook_gen.py. Validé par le validateur maison Publiciste (zéro pip) dans le job CI devops-deploy-runbook-tests. Ordonne le déploiement VPS de TOUS les livrables gated du mandat en un plan de phases dérivé de .gitea/workflows/ci.yml. Aucun chiffre métier : les paramètres non confirmés restent des confirmations sourcées.",
  "type": "object",
  "additionalProperties": false,
  "required": ["runbook", "manifest"],
  "properties": {
    "runbook": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/definitions/phase" }
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "generated_from",
        "reference_cadre",
        "cible_portage",
        "self_module",
        "counts",
        "coverage",
        "graph",
        "confirmations_ouvertes"
      ],
      "properties": {
        "generated_from": { "type": "string", "minLength": 1 },
        "reference_cadre": { "type": "string", "minLength": 1 },
        "cible_portage": { "type": "string", "minLength": 1 },
        "self_module": { "type": "string", "const": "devops/deploy_runbook" },
        "counts": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "phases",
            "modules",
            "modules_mapped",
            "confirmations",
            "confirmations_referenced"
          ],
          "properties": {
            "phases": { "type": "integer", "minimum": 1 },
            "modules": { "type": "integer", "minimum": 1 },
            "modules_mapped": { "type": "integer", "minimum": 1 },
            "confirmations": { "type": "integer", "minimum": 0 },
            "confirmations_referenced": { "type": "integer", "minimum": 0 }
          }
        },
        "coverage": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "ci_modules_count",
            "mapped_modules_count",
            "bijective",
            "missing_in_map",
            "extra_in_map",
            "unknown_phase",
            "self_module_excluded"
          ],
          "properties": {
            "ci_modules_count": { "type": "integer", "minimum": 1 },
            "mapped_modules_count": { "type": "integer", "minimum": 1 },
            "bijective": { "type": "boolean", "const": true },
            "missing_in_map": {
              "type": "array",
              "uniqueItems": true,
              "items": { "type": "string", "minLength": 1 }
            },
            "extra_in_map": {
              "type": "array",
              "uniqueItems": true,
              "items": { "type": "string", "minLength": 1 }
            },
            "unknown_phase": {
              "type": "array",
              "uniqueItems": true,
              "items": { "type": "string", "minLength": 1 }
            },
            "self_module_excluded": { "type": "string", "const": "devops/deploy_runbook" }
          }
        },
        "graph": {
          "type": "object",
          "additionalProperties": false,
          "required": ["phase_order", "orphan_confirmations", "unknown_confirmations"],
          "properties": {
            "phase_order": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": { "type": "string", "pattern": "^[a-z0-9-]+$" }
            },
            "orphan_confirmations": {
              "type": "array",
              "uniqueItems": true,
              "items": { "type": "string", "minLength": 1 }
            },
            "unknown_confirmations": {
              "type": "array",
              "uniqueItems": true,
              "items": { "type": "string", "minLength": 1 }
            }
          }
        },
        "confirmations_ouvertes": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    }
  },
  "definitions": {
    "phase": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "order",
        "id",
        "titre",
        "responsable",
        "rationale",
        "depends_on",
        "modules",
        "confirmations"
      ],
      "properties": {
        "order": { "type": "integer", "minimum": 1 },
        "id": { "type": "string", "pattern": "^[a-z0-9-]+$" },
        "titre": { "type": "string", "minLength": 1 },
        "responsable": { "type": "string", "enum": ["worker", "vps", "worker+vps"] },
        "rationale": { "type": "string", "minLength": 1 },
        "depends_on": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^[a-z0-9-]+$" }
        },
        "modules": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/definitions/module" }
        },
        "confirmations": {
          "type": "array",
          "items": { "$ref": "#/definitions/confirmation" }
        }
      }
    },
    "module": {
      "type": "object",
      "additionalProperties": false,
      "required": ["module", "ci_job"],
      "properties": {
        "module": { "type": "string", "minLength": 1 },
        "ci_job": { "type": "string", "minLength": 1 }
      }
    },
    "confirmation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "libelle", "owner", "source"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9_]+$" },
        "libelle": { "type": "string", "minLength": 1 },
        "owner": { "type": "string", "minLength": 1 },
        "source": { "type": "string", "minLength": 1 }
      }
    }
  }
}
