"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostRulesMigration = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const abstract_migration_1 = require("../base/abstract-migration");
class HostRulesMigration extends abstract_migration_1.AbstractMigration {
    constructor() {
        super(...arguments);
        this.propertyName = 'hostRules';
    }
    run(value) {
        const newHostRules = [];
        for (const hostRule of value) {
            const newRule = {};
            for (const [key, value] of Object.entries(hostRule)) {
                if (key === 'platform') {
                    if (is_1.default.string(value)) {
                        newRule.hostType ?? (newRule.hostType = value);
                    }
                    continue;
                }
                if (key === 'matchHost') {
                    if (is_1.default.string(value)) {
                        newRule.matchHost ?? (newRule.matchHost = massageUrl(value));
                    }
                    continue;
                }
                if (key === 'endpoint' ||
                    key === 'host' ||
                    key === 'baseUrl' ||
                    key === 'hostName' ||
                    key === 'domainName') {
                    if (is_1.default.string(value)) {
                        newRule.matchHost ?? (newRule.matchHost = massageUrl(value));
                    }
                    continue;
                }
                newRule[key] = value;
            }
            newHostRules.push(newRule);
        }
        this.rewrite(newHostRules);
    }
}
exports.HostRulesMigration = HostRulesMigration;
function massageUrl(url) {
    if (!url.includes('://') && url.includes('/')) {
        return 'https://' + url;
    }
    else {
        return url;
    }
}
//# sourceMappingURL=host-rules-migration.js.map