"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListOfValuesSelectionProvider = void 0;
const list_of_values_service_1 = require("../list-of-values.service");
const selection_provider_decorator_1 = require("../../decorators/selection-provider.decorator");
const common_1 = require("@nestjs/common");
const basic_filters_dto_1 = require("../../dtos/basic-filters.dto");
const DEFAULT_LIMIT = 100;
let ListOfValuesSelectionProvider = class ListOfValuesSelectionProvider {
    constructor(listOfValuesService) {
        this.listOfValuesService = listOfValuesService;
    }
    name() {
        return 'ListOfValuesSelectionProvider';
    }
    help() {
        return "# This is lov proivder";
    }
    value(optionValue, ctxt) {
        const lov = this.listOfValuesService.findOneByValueAndType(optionValue, ctxt.type);
        throw new Error("Method not implemented.");
    }
    async values(query, ctxt) {
        const basicFilterQuery = new basic_filters_dto_1.BasicFilterDto(DEFAULT_LIMIT, 0);
        if (ctxt.type) {
            basicFilterQuery.filters = {
                type: {
                    $eq: ctxt.type
                }
            };
        }
        if (query) {
            basicFilterQuery.filters = {
                ...basicFilterQuery.filters,
                display: {
                    $containsi: `%${query}%`
                }
            };
        }
        const lovs = await this.listOfValuesService.find(basicFilterQuery);
        const selectionValues = lovs.records.map(lov => {
            return {
                label: lov.display,
                value: lov.value
            };
        });
        return selectionValues;
    }
};
exports.ListOfValuesSelectionProvider = ListOfValuesSelectionProvider;
exports.ListOfValuesSelectionProvider = ListOfValuesSelectionProvider = __decorate([
    (0, selection_provider_decorator_1.SelectionProvider)(),
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [list_of_values_service_1.ListOfValuesService])
], ListOfValuesSelectionProvider);
//# sourceMappingURL=list-of-values-selection-providers.service.js.map