{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://lcm/schemas/pav1/lifecycle.schema.json",
    "title": "PAv1 lifecycle.yaml",
    "description": "Lifecycle pipeline definitions, one per phase. ADR-044 / AD-CSI-023. The document is a map of phase-name -> Pipeline; there is no top-level 'phases' envelope.",
    "type": "object",
    "minProperties": 1,
    "additionalProperties": {
        "$ref": "#/$defs/Pipeline"
    },
    "$defs": {
        "Pipeline": {
            "type": "object",
            "required": ["steps"],
            "properties": {
                "description": { "type": "string" },
                "trigger": { "type": "string" },
                "max_retries": { "type": "integer", "minimum": 0 },
                "retry_backoff": { "type": "integer", "minimum": 0 },
                "extends": { "type": "string" },
                "insert_after": { "type": "object" },
                "insert_before": { "type": "object" },
                "overrides": { "type": "object" },
                "remove": { "type": "array", "items": { "type": "string" } },
                "steps": { "type": "array", "items": { "$ref": "#/$defs/Step" } },
                "outputs": { "type": "object" }
            }
        },
        "Step": {
            "type": "object",
            "required": ["name", "handler"],
            "properties": {
                "name": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
                "handler": { "type": "string", "minLength": 1 },
                "description": { "type": "string" },
                "needs": { "type": "array", "items": { "type": "string" } },
                "skip_when": { "type": "string" },
                "timeout_seconds": { "type": "integer", "minimum": 1 },
                "optional": { "type": "boolean" },
                "inputs": { "type": "object" },
                "retry": {
                    "type": "object",
                    "properties": {
                        "max_attempts": { "type": "integer", "minimum": 1 },
                        "delay_seconds": { "type": "integer", "minimum": 0 }
                    }
                }
            }
        }
    }
}
