"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConcatEntityComputedFieldProvider = void 0;
const common_1 = require("@nestjs/common");
const lodash_1 = require("lodash");
const computed_field_provider_decorator_1 = require("../../../decorators/computed-field-provider.decorator");
let ConcatEntityComputedFieldProvider = class ConcatEntityComputedFieldProvider {
    name() {
        return "ConcatEntityComputedFieldProvider";
    }
    help() {
        return "Computed field provider used to create fields whose value is a concatenation of other fields in the same model.";
    }
    async preComputeValue(triggerEntity, computedFieldMetadata) {
        const { computedFieldValueProviderCtxt } = computedFieldMetadata;
        const separator = computedFieldValueProviderCtxt.separator ?? ' ';
        const fields = computedFieldValueProviderCtxt.fields ?? [];
        const slugify = computedFieldValueProviderCtxt.slugify ?? false;
        const parts = [];
        for (const fieldExpr of fields) {
            let val = (0, lodash_1.get)(triggerEntity, fieldExpr);
            if (val == null)
                continue;
            if (typeof val !== 'string') {
                val = String(val);
            }
            if (slugify) {
                val = (0, lodash_1.kebabCase)(val);
            }
            if (val.length > 0) {
                parts.push(val);
            }
        }
        const concatenatedString = parts.join(separator);
        triggerEntity[computedFieldMetadata.fieldName] = concatenatedString;
    }
};
exports.ConcatEntityComputedFieldProvider = ConcatEntityComputedFieldProvider;
exports.ConcatEntityComputedFieldProvider = ConcatEntityComputedFieldProvider = __decorate([
    (0, computed_field_provider_decorator_1.ComputedFieldProvider)(),
    (0, common_1.Injectable)()
], ConcatEntityComputedFieldProvider);
//# sourceMappingURL=concat-entity-computed-field-provider.service.js.map