"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScopeMismatchError = exports.RequestScopeError = exports.CyclicDependencyError = exports.DuplicateProviderError = exports.ProviderNotFoundError = void 0;
exports.formatToken = formatToken;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-server-foundation/type-metadata-runtime"));
const types_1 = require("../types");
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":2,\"typeName\":\"Token\"},{\"kind\":14,\"type\":{\"kind\":2,\"typeName\":\"Token\"}},{\"kind\":6}]]", []);
let _ProviderNotFoundErrorMetadata_1;
class ProviderNotFoundError extends Error {
    constructor(token, chain = []) {
        const dependencyChain = [...chain, token].map(formatToken).join(' -> ');
        super(`No provider found for ${formatToken(token)}${dependencyChain ? ` (dependency chain: ${dependencyChain})` : ''}`);
        this.name = 'ProviderNotFoundError';
    }
    static __tsfType = _ProviderNotFoundErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"ProviderNotFoundError\",\"typeName\":\"ProviderNotFoundError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"token\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"chain\",\"type\":{\"$tsfType\":1},\"optional\":true,\"default\":true}]}]", [() => ProviderNotFoundError], __tsf_metadata_type);
}
exports.ProviderNotFoundError = ProviderNotFoundError;
_ProviderNotFoundErrorMetadata_1.classType = ProviderNotFoundError;
ProviderNotFoundError.__tsfType = _ProviderNotFoundErrorMetadata_1;
let _DuplicateProviderErrorMetadata_1;
class DuplicateProviderError extends Error {
    constructor(token, scope) {
        super(`Duplicate provider for ${formatToken(token)} in ${scope}`);
        this.name = 'DuplicateProviderError';
    }
    static __tsfType = _DuplicateProviderErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"DuplicateProviderError\",\"typeName\":\"DuplicateProviderError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"token\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"scope\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}]}]", [() => DuplicateProviderError], __tsf_metadata_type);
}
exports.DuplicateProviderError = DuplicateProviderError;
_DuplicateProviderErrorMetadata_1.classType = DuplicateProviderError;
DuplicateProviderError.__tsfType = _DuplicateProviderErrorMetadata_1;
let _CyclicDependencyErrorMetadata_1;
class CyclicDependencyError extends Error {
    constructor(chain) {
        super(`Cyclic dependency detected: ${chain.map(formatToken).join(' -> ')}`);
        this.name = 'CyclicDependencyError';
    }
    static __tsfType = _CyclicDependencyErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"CyclicDependencyError\",\"typeName\":\"CyclicDependencyError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"chain\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}]}]", [() => CyclicDependencyError], __tsf_metadata_type);
}
exports.CyclicDependencyError = CyclicDependencyError;
_CyclicDependencyErrorMetadata_1.classType = CyclicDependencyError;
CyclicDependencyError.__tsfType = _CyclicDependencyErrorMetadata_1;
let _RequestScopeErrorMetadata_1;
class RequestScopeError extends Error {
    constructor(token) {
        super(`Cannot resolve request-scoped provider ${formatToken(token)} without a request context`);
        this.name = 'RequestScopeError';
    }
    static __tsfType = _RequestScopeErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"RequestScopeError\",\"typeName\":\"RequestScopeError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"token\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false}]}]", [() => RequestScopeError], __tsf_metadata_type);
}
exports.RequestScopeError = RequestScopeError;
_RequestScopeErrorMetadata_1.classType = RequestScopeError;
RequestScopeError.__tsfType = _RequestScopeErrorMetadata_1;
let _ScopeMismatchErrorMetadata_1;
class ScopeMismatchError extends Error {
    constructor(token, chain) {
        super(`Cannot inject request-scoped provider ${formatToken(token)} into singleton dependency chain: ${chain.map(formatToken).join(' -> ')}`);
        this.name = 'ScopeMismatchError';
    }
    static __tsfType = _ScopeMismatchErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"ScopeMismatchError\",\"typeName\":\"ScopeMismatchError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"token\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"chain\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}]}]", [() => ScopeMismatchError], __tsf_metadata_type);
}
exports.ScopeMismatchError = ScopeMismatchError;
_ScopeMismatchErrorMetadata_1.classType = ScopeMismatchError;
ScopeMismatchError.__tsfType = _ScopeMismatchErrorMetadata_1;
function formatToken(token) {
    if (typeof token === 'symbol')
        return token.toString();
    if (typeof token === 'function')
        return (0, types_1.getClassName)(token);
    if (typeof token === 'bigint')
        return token.toString();
    return JSON.stringify(token);
}
//# sourceMappingURL=errors.js.map