import { equalsIgnoreCase } from '../../../base/common/strings.js';
import { createDecorator } from '../../instantiation/common/instantiation.js';
import { getRemoteName } from '../../remote/common/remoteHosts.js';
const USER_MANIFEST_CACHE_FILE = 'extensions.user.cache';
const BUILTIN_MANIFEST_CACHE_FILE = 'extensions.builtin.cache';
const UNDEFINED_PUBLISHER = 'undefined_publisher';
const ALL_EXTENSION_KINDS = ['ui', 'workspace', 'web'];
function getWorkspaceSupportTypeMessage(supportType) {
    if (typeof supportType === 'object' && supportType !== null) {
        if (supportType.supported !== true) {
            return supportType.description;
        }
    }
    return undefined;
}
const EXTENSION_CATEGORIES = [
    'Azure',
    'Data Science',
    'Debuggers',
    'Extension Packs',
    'Education',
    'Formatters',
    'Keymaps',
    'Language Packs',
    'Linters',
    'Machine Learning',
    'Notebooks',
    'Programming Languages',
    'SCM Providers',
    'Snippets',
    'Testing',
    'Themes',
    'Visualization',
    'AI',
    'Chat',
    'Other',
];
class ExtensionIdentifier {
    constructor(value) {
        this.value = value;
        this._lower = value.toLowerCase();
    }
    static equals(a, b) {
        if (typeof a === 'undefined' || a === null) {
            return (typeof b === 'undefined' || b === null);
        }
        if (typeof b === 'undefined' || b === null) {
            return false;
        }
        if (typeof a === 'string' || typeof b === 'string') {
            const aValue = (typeof a === 'string' ? a : a.value);
            const bValue = (typeof b === 'string' ? b : b.value);
            return equalsIgnoreCase(aValue, bValue);
        }
        return (a._lower === b._lower);
    }
    static toKey(id) {
        if (typeof id === 'string') {
            return id.toLowerCase();
        }
        return id._lower;
    }
}
class ExtensionIdentifierSet {
    get size() {
        return this._set.size;
    }
    constructor(iterable) {
        this._set = ( new Set());
        if (iterable) {
            for (const value of iterable) {
                this.add(value);
            }
        }
    }
    add(id) {
        this._set.add(ExtensionIdentifier.toKey(id));
    }
    delete(extensionId) {
        return this._set.delete(ExtensionIdentifier.toKey(extensionId));
    }
    has(id) {
        return ( this._set.has(ExtensionIdentifier.toKey(id)));
    }
}
class ExtensionIdentifierMap {
    constructor() {
        this._map = ( new Map());
    }
    clear() {
        this._map.clear();
    }
    delete(id) {
        this._map.delete(ExtensionIdentifier.toKey(id));
    }
    get(id) {
        return this._map.get(ExtensionIdentifier.toKey(id));
    }
    has(id) {
        return ( this._map.has(ExtensionIdentifier.toKey(id)));
    }
    set(id, value) {
        this._map.set(ExtensionIdentifier.toKey(id), value);
    }
    values() {
        return ( this._map.values());
    }
    forEach(callbackfn) {
        this._map.forEach(callbackfn);
    }
    [Symbol.iterator]() {
        return this._map[Symbol.iterator]();
    }
}
function isApplicationScopedExtension(manifest) {
    return isLanguagePackExtension(manifest);
}
function isLanguagePackExtension(manifest) {
    return manifest.contributes && manifest.contributes.localizations ? manifest.contributes.localizations.length > 0 : false;
}
function isAuthenticationProviderExtension(manifest) {
    return manifest.contributes && manifest.contributes.authentication ? manifest.contributes.authentication.length > 0 : false;
}
function isResolverExtension(manifest, remoteAuthority) {
    if (remoteAuthority) {
        const activationEvent = `onResolveRemoteAuthority:${getRemoteName(remoteAuthority)}`;
        return !!manifest.activationEvents?.includes(activationEvent);
    }
    return false;
}
const IBuiltinExtensionsScannerService = ( createDecorator('IBuiltinExtensionsScannerService'));
export { ALL_EXTENSION_KINDS, BUILTIN_MANIFEST_CACHE_FILE, EXTENSION_CATEGORIES, ExtensionIdentifier, ExtensionIdentifierMap, ExtensionIdentifierSet, IBuiltinExtensionsScannerService, UNDEFINED_PUBLISHER, USER_MANIFEST_CACHE_FILE, getWorkspaceSupportTypeMessage, isApplicationScopedExtension, isAuthenticationProviderExtension, isLanguagePackExtension, isResolverExtension };
