"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DecimalFieldCrudManager = void 0;
const class_validator_1 = require("class-validator");
class DecimalFieldCrudManager {
    constructor(options) {
        this.options = options;
    }
    validate(createDto) {
        const fieldValue = createDto[this.options.fieldName];
        return this.applyValidations(fieldValue);
    }
    applyValidations(fieldValue) {
        const errors = [];
        this.isApplyRequiredValidation() && (0, class_validator_1.isEmpty)(fieldValue) ? errors.push({ field: this.options.fieldName, error: `Field: ${this.options.fieldName} is required` }) : "no errors";
        if ((0, class_validator_1.isNotEmpty)(fieldValue)) {
            errors.push(...this.applyFormatValidations(fieldValue));
        }
        return errors;
    }
    applyFormatValidations(fieldValue) {
        const errors = [];
        !(0, class_validator_1.isNumber)(fieldValue) ? errors.push({ field: this.options.fieldName, error: 'Field is not a decimal' }) : "no errors";
        this.isApplyMinValidation() && !(0, class_validator_1.min)(fieldValue, this.options.min) ? errors.push({ field: this.options.fieldName, error: 'Field value is lesser than minimum required' }) : "no errors";
        this.isApplyMaxValidation() && !(0, class_validator_1.max)(fieldValue, this.options.max) ? errors.push({ field: this.options.fieldName, error: 'Field value is greater than maximum required' }) : "no errors";
        return errors;
    }
    transformForCreate(createDto) {
        return createDto;
    }
    isApplyMinValidation() {
        return this.options.min > 0;
    }
    isApplyMaxValidation() {
        return this.options.max > 0;
    }
    isApplyRequiredValidation() {
        return this.options.required;
    }
}
exports.DecimalFieldCrudManager = DecimalFieldCrudManager;
//# sourceMappingURL=DecimalFieldCrudManager.js.map