"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildCodexMcpInstallCommand = buildCodexMcpInstallCommand;
exports.buildCodexMcpRemoveCommand = buildCodexMcpRemoveCommand;
function buildCodexMcpInstallCommand(serverName, spec) {
    if (spec.transport === "stdio") {
        if (spec.cwd !== undefined) {
            throw new Error("Codex MCP install does not support catalog stdio cwd. Use a command that sets its own working directory or a Claude-specific server spec.");
        }
        return [
            "codex",
            "mcp",
            "add",
            serverName,
            ...Object.entries(spec.env ?? {}).flatMap(([key, value]) => [
                "--env",
                `${key}=${value}`,
            ]),
            "--",
            spec.command,
            ...(spec.args ?? []),
        ];
    }
    if (spec.env !== undefined || spec.headers !== undefined) {
        throw new Error("Codex MCP install supports remote URL registration and bearer token env vars, but not remote env or arbitrary headers.");
    }
    return [
        "codex",
        "mcp",
        "add",
        serverName,
        "--url",
        spec.url,
        ...(spec.bearerTokenEnvVar === undefined
            ? []
            : ["--bearer-token-env-var", spec.bearerTokenEnvVar]),
    ];
}
function buildCodexMcpRemoveCommand(serverName) {
    return ["codex", "mcp", "remove", serverName];
}
