{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Finalizer Output",
  "type": "object",
  "required": [
    "task_id",
    "ready_to_finalize",
    "code_review",
    "security_review",
    "acceptance_review",
    "ci_status",
    "final_action"
  ],
  "properties": {
    "task_id": { "type": "string", "minLength": 1 },
    "ready_to_finalize": { "type": "boolean" },
    "code_review": { "type": "string", "enum": ["pass", "fail"] },
    "security_review": { "type": "string", "enum": ["pass", "fail"] },
    "acceptance_review": { "type": "string", "enum": ["pass", "fail"] },
    "ci_status": { "type": "string", "enum": ["pass", "fail", "unknown"] },
    "final_action": { "type": "string", "enum": ["commit", "merge", "hold"] },
    "hold_reason": { "type": "string", "minLength": 1 },
    "commit_message": { "type": "string" },
    "notes": { "type": "string" }
  },
  "allOf": [
    {
      "if": {
        "properties": { "final_action": { "const": "hold" } },
        "required": ["final_action"]
      },
      "then": {
        "required": ["hold_reason"]
      }
    },
    {
      "if": {
        "properties": { "final_action": { "enum": ["commit", "merge"] } },
        "required": ["final_action"]
      },
      "then": {
        "properties": {
          "ready_to_finalize": { "const": true },
          "code_review": { "const": "pass" },
          "security_review": { "const": "pass" },
          "acceptance_review": { "const": "pass" },
          "ci_status": { "const": "pass" }
        }
      }
    },
    {
      "if": {
        "properties": { "ci_status": { "enum": ["fail", "unknown"] } },
        "required": ["ci_status"]
      },
      "then": {
        "properties": { "final_action": { "const": "hold" } }
      }
    },
    {
      "if": {
        "properties": { "code_review": { "const": "fail" } },
        "required": ["code_review"]
      },
      "then": {
        "properties": { "final_action": { "const": "hold" } }
      }
    },
    {
      "if": {
        "properties": { "security_review": { "const": "fail" } },
        "required": ["security_review"]
      },
      "then": {
        "properties": { "final_action": { "const": "hold" } }
      }
    },
    {
      "if": {
        "properties": { "acceptance_review": { "const": "fail" } },
        "required": ["acceptance_review"]
      },
      "then": {
        "properties": { "final_action": { "const": "hold" } }
      }
    },
    {
      "if": {
        "properties": { "ready_to_finalize": { "const": false } },
        "required": ["ready_to_finalize"]
      },
      "then": {
        "properties": { "final_action": { "const": "hold" } }
      }
    }
  ],
  "additionalProperties": false
}
