// src/backends/codex/args.ts
function buildCodexArgs(input) {
  const args = [
    "exec",
    "--json",
    "--full-auto",
    "--skip-git-repo-check"
  ];
  if (input.agent.model) {
    const modelId = input.agent.model.id;
    args.push("--model", modelId);
    const cloudPrefixes = ["claude-", "gpt-", "o1-", "o3-", "o4-", "codex-", "chatgpt-"];
    const isOllama = !modelId.includes("/") && !cloudPrefixes.some((p) => modelId.startsWith(p));
    if (isOllama) {
      args.push("--oss", "--local-provider", "ollama");
    }
  }
  if (input.agent.mcp_servers) {
    for (const server of input.agent.mcp_servers) {
      const name = server.name;
      if (server.type) {
        args.push("-c", `mcp_servers.${name}.type="${server.type}"`);
      }
      if (server.url) {
        args.push("-c", `mcp_servers.${name}.url="${server.url}"`);
      }
      const command = server.command;
      if (typeof command === "string") {
        args.push("-c", `mcp_servers.${name}.command="${command}"`);
      }
      const sArgs = server.args;
      if (sArgs && sArgs.length > 0) {
        args.push(
          "-c",
          `mcp_servers.${name}.args=${JSON.stringify(sArgs)}`
        );
      }
      const headers = server.headers;
      if (headers) {
        for (const [hk, hv] of Object.entries(headers)) {
          args.push("-c", `mcp_servers.${name}.http_headers.${hk}="${hv}"`);
        }
      }
    }
  }
  args.push("-");
  return args;
}

export {
  buildCodexArgs
};
