"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelBackendNotFoundError = void 0;
exports.setEmbedding = setEmbedding;
exports.setGenerative = setGenerative;
exports.resolveEmbedding = resolveEmbedding;
exports.resolveGenerative = resolveGenerative;
exports.clearRegistry = clearRegistry;
const hdbError_ts_1 = require("../../utility/errors/hdbError.js");
const embedding = new Map();
const generative = new Map();
/** Map `logicalName` to a backend for embedding calls. Re-set replaces. */
function setEmbedding(logicalName, backend) {
    embedding.set(logicalName, backend);
}
/** Map `logicalName` to a backend for generative calls. Re-set replaces. */
function setGenerative(logicalName, backend) {
    generative.set(logicalName, backend);
}
/**
 * Resolve the embedding backend mapped to `logicalName` (default: `'default'`).
 * Throws `ModelBackendNotFoundError` if no backend is mapped.
 */
function resolveEmbedding(logicalName = 'default') {
    const backend = embedding.get(logicalName);
    if (!backend)
        throw new ModelBackendNotFoundError('embedding', logicalName);
    return backend;
}
/**
 * Resolve the generative backend mapped to `logicalName` (default: `'default'`).
 * Throws `ModelBackendNotFoundError` if no backend is mapped.
 */
function resolveGenerative(logicalName = 'default') {
    const backend = generative.get(logicalName);
    if (!backend)
        throw new ModelBackendNotFoundError('generative', logicalName);
    return backend;
}
/** Remove all registrations. Test-only hygiene. */
function clearRegistry() {
    embedding.clear();
    generative.clear();
}
class ModelBackendNotFoundError extends hdbError_ts_1.ServerError {
    // Message identifies the kind + logical name only; never enumerates other
    // registered names to avoid leaking the registry shape in error responses.
    constructor(kind, logicalName) {
        super(`No backend registered for '${kind}.${logicalName}'`);
        this.name = 'ModelBackendNotFoundError';
    }
}
exports.ModelBackendNotFoundError = ModelBackendNotFoundError;
//# sourceMappingURL=backendRegistry.js.map