"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCardinalityMessage = void 0;
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var ramda_1 = require("ramda");
var valueCaption = function (value) {
    return ui_i18n_1.default.text('${value}', {
        value: value === 1 ? ui_i18n_1.default.text('value') : ui_i18n_1.default.text('values')
    });
};
var hasMinValue = (0, ramda_1.has)('minValue');
var hasMaxValue = (0, ramda_1.has)('maxValue');
var noMaxValue = (0, ramda_1.pipe)(hasMaxValue, ramda_1.not);
var minValueIsOne = (0, ramda_1.propSatisfies)(function (minValue) { return minValue === 1; }, 'minValue');
var exactCardinality = function (_a) {
    var minValue = _a.minValue, maxValue = _a.maxValue;
    return minValue && minValue === maxValue;
};
var generateMinCardinality = function (_a) {
    var minValue = _a.minValue;
    return ui_i18n_1.default.text('This attribute can have minimum ${minValue} ${minValueCaption}', {
        minValue: ui_i18n_1.default.number(minValue, '0'),
        minValueCaption: valueCaption(minValue)
    });
};
var generateMaxCardinality = function (_a) {
    var maxValue = _a.maxValue;
    return ui_i18n_1.default.text('This attribute can have maximum ${maxValue} ${maxValueCaption}', {
        maxValue: ui_i18n_1.default.number(maxValue, '0'),
        maxValueCaption: valueCaption(maxValue)
    });
};
var generateExactCardinality = function (_a) {
    var minValue = _a.minValue;
    return ui_i18n_1.default.text('This attribute should have ${minValue} ${minValueCaption}', {
        minValue: ui_i18n_1.default.number(minValue, '0'),
        minValueCaption: valueCaption(minValue)
    });
};
var generateMinMaxCardinality = function (_a) {
    var minValue = _a.minValue, maxValue = _a.maxValue;
    return ui_i18n_1.default.text('${minCardinality} and maximum ${maxValue} ${maxValueCaption}', {
        minCardinality: generateMinCardinality({ minValue: minValue }),
        maxValue: ui_i18n_1.default.number(maxValue, '0'),
        maxValueCaption: valueCaption(maxValue)
    });
};
exports.getCardinalityMessage = (0, ramda_1.cond)([
    [ramda_1.isNil, (0, ramda_1.always)('')],
    [exactCardinality, generateExactCardinality],
    [(0, ramda_1.allPass)([minValueIsOne, hasMaxValue]), generateMaxCardinality],
    [(0, ramda_1.allPass)([minValueIsOne, noMaxValue]), (0, ramda_1.always)('')],
    [(0, ramda_1.allPass)([hasMinValue, hasMaxValue]), generateMinMaxCardinality],
    [hasMaxValue, generateMaxCardinality],
    [hasMinValue, generateMinCardinality],
    [ramda_1.T, (0, ramda_1.always)('')]
]);
