import { normalizeAppFlags } from "../constants.js";
import { createId } from "../utils/id.js";
export function buildMcpFromInput(input) {
    return {
        id: createId("mcp"),
        name: input.name,
        server: input.server,
        description: input.description,
        apps: normalizeAppFlags(input.apps),
    };
}
export function mergeMcp(current, patch) {
    return {
        ...current,
        name: patch.name ?? current.name,
        server: patch.server ?? current.server,
        description: patch.description ?? current.description,
        apps: patch.apps
            ? {
                ...current.apps,
                ...normalizeAppFlags({ ...current.apps, ...patch.apps }),
            }
            : current.apps,
    };
}
export function applyMcpAppFlag(server, appId, enabled) {
    const canonicalAppId = appId === "claude" ? "claudecode" : appId;
    const apps = {
        ...server.apps,
        [canonicalAppId]: enabled,
        claude: false,
    };
    return {
        ...server,
        apps,
    };
}
