"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Check = void 0;
const errors_js_1 = require("../../errors.js");
const index_js_1 = require("../serialize/index.js");
class Check {
    connection;
    name;
    dbVersionSupport;
    consistencyLevel;
    tenant;
    constructor(connection, name, dbVersionSupport, consistencyLevel, tenant) {
        this.connection = connection;
        this.name = name;
        this.dbVersionSupport = dbVersionSupport;
        this.consistencyLevel = consistencyLevel;
        this.tenant = tenant;
    }
    getSearcher = () => this.connection.search(this.name, this.consistencyLevel, this.tenant);
    checkSupportForVectors = async (vec) => {
        if (vec === undefined || index_js_1.Serialize.isHybridNearTextSearch(vec))
            return false;
        const check = await this.dbVersionSupport.supportsVectorsFieldInGRPC();
        return check.supports;
    };
    supportForSingleGroupedGenerative = async () => {
        const check = await this.dbVersionSupport.supportsSingleGrouped();
        if (!check.supports)
            throw new errors_js_1.WeaviateUnsupportedFeatureError(check.message);
        return check.supports;
    };
    supportForGenerativeConfigRuntime = async (generativeConfig) => {
        if (generativeConfig === undefined)
            return true;
        const check = await this.dbVersionSupport.supportsGenerativeConfigRuntime();
        if (!check.supports)
            throw new errors_js_1.WeaviateUnsupportedFeatureError(check.message);
        return check.supports;
    };
    nearSearch = () => this.getSearcher().then((search) => ({ search }));
    nearVector = (vec, opts) => {
        return Promise.all([this.getSearcher(), this.checkSupportForVectors(vec)]).then(([search, supportsVectors]) => {
            const is129 = supportsVectors;
            return {
                search,
                supportsVectors: is129,
            };
        });
    };
    hybridSearch = (opts) => {
        return Promise.all([this.getSearcher(), this.checkSupportForVectors(opts?.vector)]).then(([search, supportsVectors]) => {
            const is129 = supportsVectors;
            return {
                search,
                supportsVectors: is129,
            };
        });
    };
    fetchObjects = () => this.getSearcher().then((search) => ({ search }));
    fetchObjectById = () => this.getSearcher().then((search) => ({ search }));
    bm25 = () => this.getSearcher().then((search) => ({ search }));
}
exports.Check = Check;
