
import { equals } from '../../../../base/common/arrays.js';
import { assertNever } from '../../../../base/common/assert.js';
import { equals as equals$1 } from '../../../../base/common/objects.js';
import { URI } from '../../../../base/common/uri.js';
import { localize } from '../../../../nls.js';
import { ExtensionIdentifier } from '../../../../platform/extensions/common/extensions.js';

const extensionMcpCollectionPrefix = 'ext.';
function extensionPrefixedIdentifier(identifier, id) {
    return ExtensionIdentifier.toKey(identifier) + '/' + id;
}
var McpCollectionSortOrder;
(function (McpCollectionSortOrder) {
    McpCollectionSortOrder[McpCollectionSortOrder["WorkspaceFolder"] = 0] = "WorkspaceFolder";
    McpCollectionSortOrder[McpCollectionSortOrder["Workspace"] = 100] = "Workspace";
    McpCollectionSortOrder[McpCollectionSortOrder["User"] = 200] = "User";
    McpCollectionSortOrder[McpCollectionSortOrder["Extension"] = 300] = "Extension";
    McpCollectionSortOrder[McpCollectionSortOrder["Filesystem"] = 400] = "Filesystem";
    McpCollectionSortOrder[McpCollectionSortOrder["RemoteBoost"] = -50] = "RemoteBoost";
})(McpCollectionSortOrder || (McpCollectionSortOrder = {}));
var McpCollectionDefinition;
(function (McpCollectionDefinition) {
    function equals(a, b) {
        return a.id === b.id
            && a.remoteAuthority === b.remoteAuthority
            && a.label === b.label
            && a.isTrustedByDefault === b.isTrustedByDefault;
    }
    McpCollectionDefinition.equals = equals;
})(McpCollectionDefinition || (McpCollectionDefinition = {}));
var McpServerDefinition;
(function (McpServerDefinition) {
    function toSerialized(def) {
        return def;
    }
    McpServerDefinition.toSerialized = toSerialized;
    function fromSerialized(def) {
        return {
            id: def.id,
            label: def.label,
            cacheNonce: def.cacheNonce,
            launch: McpServerLaunch.fromSerialized(def.launch),
            variableReplacement: def.variableReplacement ? McpServerDefinitionVariableReplacement.fromSerialized(def.variableReplacement) : undefined,
        };
    }
    McpServerDefinition.fromSerialized = fromSerialized;
    function equals$2(a, b) {
        return a.id === b.id
            && a.label === b.label
            && equals(a.roots, b.roots, (a, b) => ( a.toString()) === ( b.toString()))
            && equals$1(a.launch, b.launch)
            && equals$1(a.presentation, b.presentation)
            && equals$1(a.variableReplacement, b.variableReplacement);
    }
    McpServerDefinition.equals = equals$2;
})(McpServerDefinition || (McpServerDefinition = {}));
var McpServerDefinitionVariableReplacement;
(function (McpServerDefinitionVariableReplacement) {
    function toSerialized(def) {
        return def;
    }
    McpServerDefinitionVariableReplacement.toSerialized = toSerialized;
    function fromSerialized(def) {
        return {
            section: def.section,
            folder: def.folder ? { ...def.folder, uri: URI.revive(def.folder.uri) } : undefined,
            target: def.target,
        };
    }
    McpServerDefinitionVariableReplacement.fromSerialized = fromSerialized;
})(McpServerDefinitionVariableReplacement || (McpServerDefinitionVariableReplacement = {}));
var LazyCollectionState;
(function (LazyCollectionState) {
    LazyCollectionState[LazyCollectionState["HasUnknown"] = 0] = "HasUnknown";
    LazyCollectionState[LazyCollectionState["LoadingUnknown"] = 1] = "LoadingUnknown";
    LazyCollectionState[LazyCollectionState["AllKnown"] = 2] = "AllKnown";
})(LazyCollectionState || (LazyCollectionState = {}));
var McpServerToolsState;
(function (McpServerToolsState) {
    McpServerToolsState[McpServerToolsState["Unknown"] = 0] = "Unknown";
    McpServerToolsState[McpServerToolsState["Cached"] = 1] = "Cached";
    McpServerToolsState[McpServerToolsState["Outdated"] = 2] = "Outdated";
    McpServerToolsState[McpServerToolsState["RefreshingFromUnknown"] = 3] = "RefreshingFromUnknown";
    McpServerToolsState[McpServerToolsState["RefreshingFromCached"] = 4] = "RefreshingFromCached";
    McpServerToolsState[McpServerToolsState["Live"] = 5] = "Live";
})(McpServerToolsState || (McpServerToolsState = {}));
var McpServerTransportType;
(function (McpServerTransportType) {
    McpServerTransportType[McpServerTransportType["Stdio"] = 1] = "Stdio";
    McpServerTransportType[McpServerTransportType["HTTP"] = 2] = "HTTP";
})(McpServerTransportType || (McpServerTransportType = {}));
var McpServerLaunch;
(function (McpServerLaunch) {
    function toSerialized(launch) {
        return launch;
    }
    McpServerLaunch.toSerialized = toSerialized;
    function fromSerialized(launch) {
        switch (launch.type) {
            case McpServerTransportType.HTTP:
                return { type: launch.type, uri: URI.revive(launch.uri), headers: launch.headers };
            case McpServerTransportType.Stdio:
                return {
                    type: launch.type,
                    cwd: launch.cwd ? URI.revive(launch.cwd) : undefined,
                    command: launch.command,
                    args: launch.args,
                    env: launch.env,
                    envFile: launch.envFile,
                };
        }
    }
    McpServerLaunch.fromSerialized = fromSerialized;
})(McpServerLaunch || (McpServerLaunch = {}));
var McpConnectionState;
(function (McpConnectionState) {
    let Kind;
    (function (Kind) {
        Kind[Kind["Stopped"] = 0] = "Stopped";
        Kind[Kind["Starting"] = 1] = "Starting";
        Kind[Kind["Running"] = 2] = "Running";
        Kind[Kind["Error"] = 3] = "Error";
    })(Kind = McpConnectionState.Kind || (McpConnectionState.Kind = {}));
    McpConnectionState.toString = (s) => {
        switch (s.state) {
            case Kind.Stopped:
                return localize(7759, 'Stopped');
            case Kind.Starting:
                return localize(7760, 'Starting');
            case Kind.Running:
                return localize(7761, 'Running');
            case Kind.Error:
                return localize(7762, 'Error {0}', s.message);
            default:
                assertNever();
        }
    };
    McpConnectionState.toKindString = (s) => {
        switch (s) {
            case Kind.Stopped:
                return 'stopped';
            case Kind.Starting:
                return 'starting';
            case Kind.Running:
                return 'running';
            case Kind.Error:
                return 'error';
            default:
                assertNever();
        }
    };
    McpConnectionState.canBeStarted = (s) => s === Kind.Error || s === Kind.Stopped;
    McpConnectionState.isRunning = (s) => !McpConnectionState.canBeStarted(s.state);
})(McpConnectionState || (McpConnectionState = {}));
class MpcResponseError extends Error {
    constructor(message, code, data) {
        super(`MPC ${code}: ${message}`);
        this.code = code;
        this.data = data;
    }
}
class McpConnectionFailedError extends Error {
}

export { LazyCollectionState, McpCollectionDefinition, McpCollectionSortOrder, McpConnectionFailedError, McpConnectionState, McpServerDefinition, McpServerDefinitionVariableReplacement, McpServerLaunch, McpServerToolsState, McpServerTransportType, MpcResponseError, extensionMcpCollectionPrefix, extensionPrefixedIdentifier };
