/**
 * Represents a high-level AI model that may have multiple variants (e.g., quantized versions, different formats).
 * Manages the selection and interaction with a specific model variant.
 */
export class Model {
    _alias;
    _variants;
    selectedVariant;
    constructor(variant) {
        this._alias = variant.alias;
        this._variants = [variant];
        this.selectedVariant = variant;
    }
    /**
     * Adds a new variant to this model.
     * Automatically selects the new variant if it is cached and the current one is not.
     * @param variant - The model variant to add.
     * @throws Error - If the variant's alias does not match the model's alias.
     * @internal
     */
    addVariant(variant) {
        if (!variant || variant.alias !== this._alias) {
            throw new Error(`Variant alias "${variant?.alias}" does not match model alias "${this._alias}".`);
        }
        this._variants.push(variant);
        // prefer the highest priority locally cached variant
        if (variant.isCached && !this.selectedVariant.isCached) {
            this.selectedVariant = variant;
        }
    }
    /**
     * Selects a specific variant.
     * @param variant - The model variant to select. Must be one of the variants in `variants`.
     * @throws Error - If the variant does not belong to this model.
     */
    selectVariant(variant) {
        const matchingVariant = this._variants.find(v => v.id === variant.id);
        if (!variant.id || !matchingVariant) {
            throw new Error(`Input variant was not found in Variants.`);
        }
        this.selectedVariant = matchingVariant;
    }
    /**
     * Gets the ID of the currently selected variant.
     * @returns The ID of the selected variant.
     */
    get id() {
        return this.selectedVariant.id;
    }
    /**
     * Gets the alias of the model.
     * @returns The model alias.
     */
    get alias() {
        return this._alias;
    }
    /**
     * Gets the ModelInfo of the currently selected variant.
     * @returns The ModelInfo object.
     */
    get info() {
        return this.selectedVariant.info;
    }
    /**
     * Checks if the currently selected variant is cached locally.
     * @returns True if cached, false otherwise.
     */
    get isCached() {
        return this.selectedVariant.isCached;
    }
    /**
     * Checks if the currently selected variant is loaded in memory.
     * @returns True if loaded, false otherwise.
     */
    async isLoaded() {
        return await this.selectedVariant.isLoaded();
    }
    /**
     * Gets all available variants for this model.
     * @returns An array of IModel objects.
     */
    get variants() {
        return this._variants;
    }
    get contextLength() {
        return this.selectedVariant.contextLength;
    }
    get inputModalities() {
        return this.selectedVariant.inputModalities;
    }
    get outputModalities() {
        return this.selectedVariant.outputModalities;
    }
    get capabilities() {
        return this.selectedVariant.capabilities;
    }
    get supportsToolCalling() {
        return this.selectedVariant.supportsToolCalling;
    }
    /**
     * Downloads the currently selected variant.
     * @param progressCallback - Optional callback to report download progress.
     */
    download(progressCallback) {
        return this.selectedVariant.download(progressCallback);
    }
    /**
     * Gets the local file path of the currently selected variant.
     * @returns The local file path.
     */
    get path() {
        return this.selectedVariant.path;
    }
    /**
     * Loads the currently selected variant into memory.
     * @returns A promise that resolves when the model is loaded.
     */
    async load() {
        await this.selectedVariant.load();
    }
    /**
     * Removes the currently selected variant from the local cache.
     */
    removeFromCache() {
        this.selectedVariant.removeFromCache();
    }
    /**
     * Unloads the currently selected variant from memory.
     * @returns A promise that resolves when the model is unloaded.
     */
    async unload() {
        await this.selectedVariant.unload();
    }
    /**
     * Creates a ChatClient for interacting with the model via chat completions.
     * @returns A ChatClient instance.
     */
    createChatClient() {
        return this.selectedVariant.createChatClient();
    }
    /**
     * Creates an AudioClient for interacting with the model via audio operations.
     * @returns An AudioClient instance.
     */
    createAudioClient() {
        return this.selectedVariant.createAudioClient();
    }
    /**
     * Creates a LiveAudioTranscriptionSession for real-time audio streaming ASR.
     * @returns A LiveAudioTranscriptionSession instance.
     */
    createLiveTranscriptionSession() {
        return this.selectedVariant.createLiveTranscriptionSession();
    }
    /**
     * Creates a ResponsesClient for interacting with the model via the Responses API.
     * @param baseUrl - The base URL of the Foundry Local web service.
     * @returns A ResponsesClient instance.
     */
    createResponsesClient(baseUrl) {
        return this.selectedVariant.createResponsesClient(baseUrl);
    }
}
