"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNpmRegistryParams = exports.getRepositoryType = void 0;
const ewizardService_types_1 = require("../interfaces/ewizardService.types");
const path_1 = require("path");
const readRc_1 = require("./readRc");
function getRepositoryType(presentationPath) {
    return __awaiter(this, void 0, void 0, function* () {
        const rcFileName = '.wizrc';
        const repositoryTypeKey = 'codeartifact_repository';
        const wizRc = yield (0, readRc_1.readWizRc)((0, path_1.join)(presentationPath, rcFileName));
        if (wizRc === null || wizRc === void 0 ? void 0 : wizRc[repositoryTypeKey]) {
            const capitalizedRepositoryType = wizRc[repositoryTypeKey].replace(/^./, (match) => match.toUpperCase());
            return capitalizedRepositoryType in ewizardService_types_1.RepositoryType ? wizRc[repositoryTypeKey] : ewizardService_types_1.RepositoryType.Private;
        }
        return ewizardService_types_1.RepositoryType.Private;
    });
}
exports.getRepositoryType = getRepositoryType;
function getNpmRegistryParams(options, presentationPath, action) {
    var _a, _b;
    return __awaiter(this, void 0, void 0, function* () {
        const npmRegistryParams = {
            action,
            repositoryType: (_b = (_a = validate(options.repository)) !== null && _a !== void 0 ? _a : validate(yield getRepositoryType(presentationPath))) !== null && _b !== void 0 ? _b : ewizardService_types_1.RepositoryType.Private,
        };
        return npmRegistryParams;
    });
}
exports.getNpmRegistryParams = getNpmRegistryParams;
function validate(repository) {
    if (typeof repository === 'string') {
        const capitalizedRepositoryType = repository.replace(/^./, (match) => match.toUpperCase());
        if (capitalizedRepositoryType in ewizardService_types_1.RepositoryType) {
            return ewizardService_types_1.RepositoryType[capitalizedRepositoryType];
        }
        return null;
    }
    return null;
}
//# sourceMappingURL=codeArtifactUtils.js.map