{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://stravica.ai/schemas/runbook/1.0",
  "title": "MigrationRunbook",
  "type": "object",
  "required": ["$schema", "id", "target", "version", "steps"],
  "properties": {
    "$schema": { "type": "string" },
    "id": { "type": "string" },
    "target": { "type": "string" },
    "description": { "type": "string" },
    "version": { "type": "string" },
    "inspectionRef": { "type": "string" },
    "steps": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/Step" }
    }
  },
  "$defs": {
    "Step": {
      "type": "object",
      "required": ["id", "intent"],
      "properties": {
        "id": { "type": "string" },
        "intent": {
          "type": "string",
          "enum": [
            "snapshot-v1-fork",
            "run-migrate-to-v2",
            "rewrite-crontab",
            "drop-cron-entry",
            "update-host-service",
            "verify-sync-continuity",
            "verify-boot-health",
            "define-roster-entry"
          ]
        },
        "description": { "type": "string" },
        "params": { "type": "object" },
        "preconditions": {
          "type": "array",
          "items": { "$ref": "#/$defs/Condition" }
        },
        "expect": { "type": "object" },
        "rollback": { "$ref": "#/$defs/Rollback" },
        "notes": { "type": "string" }
      }
    },
    "Condition": {
      "type": "object",
      "required": ["assert"],
      "properties": {
        "assert": { "type": "string" },
        "value": {}
      }
    },
    "Rollback": {
      "type": "object",
      "required": ["trigger", "action"],
      "properties": {
        "trigger": { "type": "string" },
        "action": { "type": "string" }
      }
    }
  }
}
