import { merge } from '../utils/object-utils.js';
import { validations } from '../built-in-options/index.js';
const { Validations: { REQUIRED, PATTERN }, } = validations;
export default class JDLValidation {
    name;
    value;
    constructor(args) {
        const merged = merge(defaults(), args);
        this.name = merged.name;
        this.value = merged.value;
    }
    toString() {
        let string = `${this.name}`;
        if (this.value || this.value === 0) {
            string += `(${formatValidationValue(this.name, this.value)})`;
        }
        return string;
    }
}
function defaults() {
    return {
        name: REQUIRED,
        value: '',
    };
}
function formatValidationValue(name, value) {
    if (name === PATTERN) {
        return getPatternValidationValue(value);
    }
    return value;
}
function getPatternValidationValue(value) {
    if (value instanceof RegExp) {
        return value.toString();
    }
    return `/${value}/`;
}
