function transformStdioServer(config, enabled) {
    if (!enabled) {
        return undefined;
    }
    const result = {
        command: config.command
    };
    if (config.args && config.args.length > 0) {
        result.args = config.args;
    }
    if (config.env && Object.keys(config.env).length > 0) {
        result.env = config.env;
    }
    return result;
}
export function standardShape(entry) {
    const enabled = entry.enabled !== false;
    if (entry.config.transport === "stdio") {
        return transformStdioServer(entry.config, enabled);
    }
    if (!enabled) {
        return undefined;
    }
    return {
        type: "http",
        url: entry.config.url,
        ...(entry.config.headers && Object.keys(entry.config.headers).length > 0
            ? { headers: entry.config.headers }
            : {})
    };
}
function transformStdioServerOpencode(config, enabled) {
    const command = config.args && config.args.length > 0
        ? [config.command, ...config.args]
        : [config.command];
    const result = {
        type: "local",
        command,
        enabled
    };
    if (config.env && Object.keys(config.env).length > 0) {
        result.env = config.env;
    }
    return result;
}
export function opencodeShape(entry) {
    const enabled = entry.enabled !== false;
    if (entry.config.transport === "stdio") {
        return transformStdioServerOpencode(entry.config, enabled);
    }
    return {
        type: "remote",
        url: entry.config.url,
        enabled,
        ...(entry.config.headers && Object.keys(entry.config.headers).length > 0
            ? { headers: entry.config.headers }
            : {})
    };
}
export function gooseShape(entry) {
    const enabled = entry.enabled !== false;
    if (!enabled) {
        return undefined;
    }
    if (entry.config.transport === "stdio") {
        const result = {
            type: "stdio",
            cmd: entry.config.command
        };
        if (entry.config.args && entry.config.args.length > 0) {
            result.args = entry.config.args;
        }
        if (entry.config.env && Object.keys(entry.config.env).length > 0) {
            result.envs = entry.config.env;
        }
        return result;
    }
    const result = {
        type: "http",
        url: entry.config.url
    };
    if (entry.config.headers && Object.keys(entry.config.headers).length > 0) {
        result.headers = entry.config.headers;
    }
    return result;
}
const shapeTransformers = {
    standard: standardShape,
    opencode: opencodeShape,
    goose: gooseShape
};
export function getShapeTransformer(shape) {
    return shapeTransformers[shape];
}
