"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var plugin_config_interface_1 = require("./interfaces/plugin-config.interface");
var ConfigurationLoader = /** @class */ (function () {
    function ConfigurationLoader(_a) {
        var deprecateAll = _a.deprecateAll, supportLatest = _a.supportLatest, supportPreReleaseIfNotReleased = _a.supportPreReleaseIfNotReleased;
        this.deprecateAll = deprecateAll;
        this.supportLatest = supportLatest;
        this.supportPreReleaseIfNotReleased = supportPreReleaseIfNotReleased;
    }
    ConfigurationLoader.prototype.generateRules = function (pluginConfig) {
        var _this = this;
        if (!pluginConfig || !pluginConfig.rules) {
            return this.generateDefaultRules();
        }
        return pluginConfig.rules.map(function (ruleConfig, index) {
            if (typeof ruleConfig === "function") {
                return ruleConfig;
            }
            if (typeof ruleConfig === "string") {
                return _this.generateRule(ruleConfig, undefined);
            }
            if (ruleConfig.rule && typeof ruleConfig.rule === "string") {
                return _this.generateRule(ruleConfig.rule, ruleConfig.options);
            }
            throw new Error("Unsupported rule configuration at index " + index);
        });
    };
    ConfigurationLoader.prototype.generateRule = function (rule, options) {
        switch (rule) {
            case plugin_config_interface_1.SupportedDefaultRule.deprecateAll:
                return this.deprecateAll.bind(undefined, undefined);
            case plugin_config_interface_1.SupportedDefaultRule.supportLatest:
                return this.supportLatest.bind(undefined, options);
            case plugin_config_interface_1.SupportedDefaultRule.supportPreReleaseIfNotReleased:
                return this.supportPreReleaseIfNotReleased.bind(undefined, options);
            default:
                throw new Error("Unsupported rule " + rule);
        }
    };
    ConfigurationLoader.prototype.generateDefaultRules = function () {
        return [
            this.supportLatest.bind(undefined, undefined),
            this.supportPreReleaseIfNotReleased.bind(undefined, undefined),
            this.deprecateAll.bind(undefined, undefined),
        ];
    };
    return ConfigurationLoader;
}());
exports.default = ConfigurationLoader;
