"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.functionsRmallCommand = exports.FUNCTIONS_RMALL_SUBCOMMAND = void 0;
const cli_1 = require("@remotion/cli");
const lambda_client_1 = require("@remotion/lambda-client");
const get_function_info_1 = require("../../../api/get-function-info");
const get_aws_region_1 = require("../../get-aws-region");
const confirm_1 = require("../../helpers/confirm");
exports.FUNCTIONS_RMALL_SUBCOMMAND = 'rmall';
const LEFT_COL = 16;
const functionsRmallCommand = async ({ logLevel, providerSpecifics, }) => {
    const region = (0, get_aws_region_1.getAwsRegion)();
    const functions = await providerSpecifics.getFunctions({
        region,
        compatibleOnly: false,
    });
    for (const fun of functions) {
        const infoOutput = cli_1.CliInternals.createOverwriteableCliOutput({
            quiet: cli_1.CliInternals.quietFlagProvided(),
            cancelSignal: null,
            // No browser logs
            updatesDontOverwrite: false,
            indent: false,
            logLevel,
        });
        infoOutput.update('Getting function info...', false);
        const info = await (0, get_function_info_1.getFunctionInfo)({
            region,
            functionName: fun.functionName,
        });
        infoOutput.update([
            'Function name: '.padEnd(LEFT_COL, ' ') + ' ' + info.functionName,
            'Memory: '.padEnd(LEFT_COL, ' ') + ' ' + info.memorySizeInMb + 'MB',
            'Timeout: '.padEnd(LEFT_COL, ' ') + ' ' + info.timeoutInSeconds + 'sec',
            'Version: '.padEnd(LEFT_COL, ' ') + ' ' + info.version,
        ].join('\n'), true);
        if (!(await (0, confirm_1.confirmCli)({ delMessage: 'Delete? (Y/n)', allowForceFlag: true }))) {
            continue;
        }
        const output = cli_1.CliInternals.createOverwriteableCliOutput({
            quiet: cli_1.CliInternals.quietFlagProvided(),
            cancelSignal: null,
            updatesDontOverwrite: cli_1.CliInternals.shouldUseNonOverlayingLogger({
                logLevel,
            }),
            indent: false,
            logLevel,
        });
        output.update('Deleting...', false);
        await (0, lambda_client_1.deleteFunction)({ region, functionName: fun.functionName });
        output.update('Deleted!', true);
    }
};
exports.functionsRmallCommand = functionsRmallCommand;
