"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkAccountId = checkAccountId;
const tslib_1 = require("tslib");
const aws_sdk_1 = require("aws-sdk");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const awsAccountMap = {
    '343218189447': 'testnet',
    '322025165701': 'testnet',
    '946915630111': 'devnet',
    '715320985461': 'mainnet',
};
async function checkAccountId(config, show = false) {
    const sts = new aws_sdk_1.STS();
    try {
        const identity = await sts.getCallerIdentity().promise();
        const account = identity.Account;
        if (!account) {
            console.log('No AWS account ID found. Exiting...');
            process.exit(1);
        }
        if (awsAccountMap[account] === config.environment) {
            if (show) {
                console.log({}, `🌩️ Running AWS credentials for ${config.environment}`);
            }
            return;
        }
        console.log();
        console.error(chalk_1.default.yellow(`☁️❌ AWS account and App environment mismatch. `));
        console.error(`App Environment configured is ${config.environment}.`);
        console.error(`Current AWS account ID: ${account} (${awsAccountMap[account]})`);
        console.error(`Expected AWS account ID for ${config.environment} is ${Object.keys(awsAccountMap).find((key) => awsAccountMap[key] === config.environment)}`);
        console.log();
        console.error(`To avoid mistakes, please ensure you are using the correct AWS account for your environment.`);
        process.exit(1);
    }
    catch (error) {
        if (error && typeof error === 'object' && 'code' in error) {
            console.error(chalk_1.default.red('Error code received while retrieving AWS account ID:', error.code));
        }
        else {
            console.error(chalk_1.default.red('Error code received while retrieving AWS account ID:', error));
        }
        process.exit(1);
    }
}
//# sourceMappingURL=aws.js.map