"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportPreReleaseIfNotReleased = void 0;
var rule_interface_1 = require("../interfaces/rule.interface");
var DEFAULT_OPTIONS = {
    numberOfPreReleases: 1,
};
exports.supportPreReleaseIfNotReleased = function (options, version, allVersionsSortedLatestFirst) {
    var realOptions = __assign(__assign({}, DEFAULT_OPTIONS), (options || {}));
    if (!version.prerelease.length) {
        return { action: rule_interface_1.Action.continue };
    }
    var supportedPreReleases = 0;
    for (var _i = 0, allVersionsSortedLatestFirst_1 = allVersionsSortedLatestFirst; _i < allVersionsSortedLatestFirst_1.length; _i++) {
        var currentVersion = allVersionsSortedLatestFirst_1[_i];
        if (currentVersion.major === version.major &&
            currentVersion.minor === version.minor &&
            currentVersion.patch === version.patch) {
            if (currentVersion.prerelease.length) {
                supportedPreReleases += 1;
            }
            else {
                return { action: rule_interface_1.Action.continue };
            }
        }
        if (realOptions.numberOfPreReleases !== "all" &&
            supportedPreReleases > (realOptions.numberOfPreReleases || 1)) {
            return { action: rule_interface_1.Action.continue };
        }
        if (currentVersion.compare(version) === 0) {
            break;
        }
    }
    return { action: rule_interface_1.Action.support };
};
