const CONFIRM_TO_MODE = {
  apply_now: "subagent",
  plan_first: "pipeline",
  analyze_only: "explore"
};

function resolveOrchestration(taskType, confirmDefault, matrix) {
  const pattern = taskType?.orchestration_pattern || "expert_pool";
  const mode = CONFIRM_TO_MODE[confirmDefault] || "pipeline";

  const chains = (matrix?.capability_chains || []).filter(
    (c) => c.from_capability === (taskType?.capability || c.from_capability)
  );

  return {
    pattern,
    execution_mode: mode,
    chains: chains.map((c) => ({
      then_capability: c.then_capability,
      when: c.when || "after_confirm"
    }))
  };
}

module.exports = { resolveOrchestration, CONFIRM_TO_MODE };
