"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZedClient = exports.ZedMCPConfig = void 0;
const zod_1 = __importDefault(require("zod"));
const path = __importStar(require("path"));
const os = __importStar(require("os"));
const MCPClient_1 = require("../MCPClient");
const defaults_1 = require("../defaults");
exports.ZedMCPConfig = zod_1.default
    .object({
    context_servers: zod_1.default.record(zod_1.default.string(), zod_1.default.union([
        zod_1.default.object({
            enabled: zod_1.default.boolean().optional(),
            source: zod_1.default.string().optional(),
            command: zod_1.default.string().optional(),
            args: zod_1.default.array(zod_1.default.string()).optional(),
            env: zod_1.default.record(zod_1.default.string(), zod_1.default.string()).optional(),
        }),
        zod_1.default.object({
            enabled: zod_1.default.boolean().optional(),
            url: zod_1.default.string(),
            headers: zod_1.default.record(zod_1.default.string(), zod_1.default.string()).optional(),
        }),
    ])),
})
    .passthrough();
class ZedClient extends MCPClient_1.DefaultMCPClient {
    name = 'Zed';
    getServerPropertyName() {
        return 'context_servers';
    }
    async isClientSupported() {
        return Promise.resolve(process.platform === 'darwin' || process.platform === 'linux');
    }
    async getConfigPath() {
        const homeDir = os.homedir();
        const isMac = process.platform === 'darwin';
        const isLinux = process.platform === 'linux';
        if (isMac) {
            return Promise.resolve(path.join(homeDir, '.config', 'zed', 'settings.json'));
        }
        if (isLinux) {
            // https://zed.dev/docs/configuring-zed#settings-files
            const xdgConfigHome = process.env.XDG_CONFIG_HOME;
            if (xdgConfigHome) {
                return Promise.resolve(path.join(xdgConfigHome, 'zed', 'settings.json'));
            }
            return Promise.resolve(path.join(homeDir, '.config', 'zed', 'settings.json'));
        }
        throw new Error(`Unsupported platform: ${process.platform}`);
    }
    getServerConfig(apiKey, type, selectedFeatures, local, zone = 'us') {
        const config = {
            enabled: true,
            url: (0, defaults_1.buildMCPUrl)(type, selectedFeatures, local, zone),
        };
        if (apiKey) {
            config.headers = { Authorization: `Bearer ${apiKey}` };
        }
        return config;
    }
    async addServer(apiKey, selectedFeatures, local, zone = 'us') {
        return this._addServerType(apiKey, 'streamable-http', selectedFeatures, local, zone);
    }
}
exports.ZedClient = ZedClient;
