{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "OrchestrationDecision",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "task_id",
    "track",
    "risk_level",
    "recommended_gates",
    "recommended_route",
    "auto_chain",
    "chairman_required",
    "audit_required",
    "blocking_issues",
    "audit_event"
  ],
  "properties": {
    "task_id": {
      "type": "string",
      "pattern": "^task-[0-9]+(?:\\+[0-9]+)?$"
    },
    "track": {
      "type": "string",
      "enum": [
        "dev_workspace",
        "user_service",
        "internal_doc"
      ]
    },
    "risk_level": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4
    },
    "recommended_gates": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "recommended_route": {
      "type": "array",
      "maxItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phase",
          "role",
          "team"
        ],
        "properties": {
          "phase": {
            "type": "string",
            "minLength": 1
          },
          "role": {
            "type": "string",
            "minLength": 1
          },
          "team": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "auto_chain": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowed",
        "mode",
        "reason"
      ],
      "properties": {
        "allowed": {
          "const": false
        },
        "mode": {
          "const": "propose_only"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "chairman_required": {
      "type": "boolean"
    },
    "audit_required": {
      "const": true
    },
    "blocking_issues": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "code",
          "severity",
          "remediation"
        ],
        "properties": {
          "code": {
            "type": "string",
            "minLength": 1
          },
          "severity": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high",
              "critical"
            ]
          },
          "remediation": {
            "type": "string",
            "minLength": 1
          }
        },
        "additionalProperties": true
      }
    },
    "audit_event": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "event",
        "actor",
        "policy_files_used",
        "blocking_issues_count",
        "chairman_required"
      ],
      "properties": {
        "event": {
          "type": "string",
          "enum": [
            "route_recommended",
            "route_blocked",
            "validation_failed"
          ]
        },
        "actor": {
          "type": "string",
          "enum": [
            "orchestrator_subagent"
          ]
        },
        "policy_files_used": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "blocking_issues_count": {
          "type": "integer",
          "minimum": 0
        },
        "recommended_next_action": {
          "type": "string"
        },
        "chairman_required": {
          "type": "boolean"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "blocking_issues": {
            "minItems": 1
          }
        }
      },
      "then": {
        "properties": {
          "chairman_required": {
            "const": true
          }
        }
      }
    }
  ]
}