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);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
import { regionUphostMap } from '../config';
import { DEFAULT_CHUNK_SIZE } from '../upload';
export function normalizeUploadConfig(config, logger) {
    var _a = __assign({}, config), upprotocol = _a.upprotocol, uphost = _a.uphost, otherConfig = __rest(_a, ["upprotocol", "uphost"]);
    var normalizeConfig = __assign({ uphost: [], retryCount: 3, checkByMD5: false, forceDirect: false, useCdnDomain: true, checkByServer: false, concurrentRequestLimit: 3, chunkSize: DEFAULT_CHUNK_SIZE, upprotocol: 'https', debugLogLevel: 'OFF', disableStatisticsReport: false }, otherConfig);
    // 兼容原来的 http: https: 的写法
    if (upprotocol) {
        normalizeConfig.upprotocol = upprotocol
            .replace(/:$/, '');
    }
    var hostList = [];
    if (logger && (config === null || config === void 0 ? void 0 : config.uphost) != null && (config === null || config === void 0 ? void 0 : config.region) != null) {
        logger.warn('do not use both the uphost and region config.');
    }
    // 如果同时指定了 uphost 参数，添加到可用 host 列表
    if (uphost) {
        if (Array.isArray(uphost)) {
            hostList.push.apply(hostList, __spread(uphost));
        }
        else {
            hostList.push(uphost);
        }
        // 否则如果用户传了 region，添加指定 region 的 host 到可用 host 列表
    }
    else if (normalizeConfig === null || normalizeConfig === void 0 ? void 0 : normalizeConfig.region) {
        var hostMap = regionUphostMap[normalizeConfig === null || normalizeConfig === void 0 ? void 0 : normalizeConfig.region];
        if (normalizeConfig.useCdnDomain) {
            hostList.push.apply(hostList, __spread(hostMap.cdnUphost));
        }
        else {
            hostList.push.apply(hostList, __spread(hostMap.srcUphost));
        }
    }
    return __assign(__assign({}, normalizeConfig), { uphost: hostList.filter(Boolean) });
}
//# sourceMappingURL=config.js.map