"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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lerna_1 = require("../utils/lerna");
const joi_1 = __importDefault(require("@hapi/joi"));
const regions = [
    'us-east-1',
    'us-east-2',
    'us-west-1',
    'us-west-2',
    'ca-central-1',
    'eu-west-1',
    'eu-west-2',
    'eu-west-3',
    'eu-central-1',
    'ap-southeast-1',
    'ap-southeast-2',
    'ap-northeast-1',
    'ap-northeast-2',
    'ap-northeast-3',
    'eu-north-1',
    'sa-east-1',
    'cn-north-1',
    'cn-northwest-1',
    'ap-east-1',
    'me-south-1',
    'ap-south-1',
];
const buildConfigSchema = () => __awaiter(void 0, void 0, void 0, function* () {
    const lerna = new lerna_1.LernaHelper();
    const _services = yield lerna.getServices();
    const allowedServices = joi_1.default.string().valid(...this._services.map((s) => s.name));
    const regionSchema = joi_1.default.alternatives([
        joi_1.default.string().valid(regions),
        joi_1.default.array().items(joi_1.default.string().valid(regions)),
        joi_1.default.object().pattern(joi_1.default.string().alphanum(), joi_1.default.alternatives([
            joi_1.default.string().valid(regions),
            joi_1.default.array().items(joi_1.default.string().valid(regions)),
        ])),
    ]);
    this._schema = joi_1.default.object().keys({
        defaultRegions: regionSchema.optional(),
        regions: joi_1.default.object()
            .pattern(allowedServices, regionSchema)
            .optional(),
        steps: joi_1.default.array()
            .items(joi_1.default.alternatives([joi_1.default.string().valid('*'), joi_1.default.array().items(services)]))
            .optional(),
    });
});
//# sourceMappingURL=config.schema.js.map