"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SemverRangeValidator = void 0;
const semver = require("semver");
const non_empty_validator_1 = require("./non-empty-validator");
/**
 * @see [semver (look for "Ranges")](https://www.npmjs.com/package/semver)
 */
class SemverRangeValidator extends non_empty_validator_1.NonEmptyValidator {
    constructor(whyInvalid, nullable = false) {
        super(whyInvalid);
        this.nullable = nullable;
    }
    /** Checks for a well-constructed version range
     * based on semantic versioning rules.
     *
     * @see []()
     *
     * @param candidate semantic version range.
     */
    isValid(candidate) {
        let result = { isValid: true };
        if (!this.nullable) {
            result = super.isValid(candidate);
        }
        if (result.isValid) {
            if (candidate) {
                const invalidReason = semver.validRange(candidate);
                if (invalidReason != null) {
                    result.reason = invalidReason;
                    result.isValid = false;
                }
            }
        }
        return result;
    }
}
exports.SemverRangeValidator = SemverRangeValidator;
//# sourceMappingURL=semver-range-validator.js.map