"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mablApiClientFactory_1 = require("@mablhq-internal/runtime/api/mablApiClientFactory");
const constants_1 = require("@mablhq-internal/runtime/core/constants");
const cliUtil_1 = require("@mablhq-internal/runtime/core/cliUtil");
const chalk_1 = __importDefault(require("chalk"));
const loggingProvider_1 = require("@mablhq-internal/runtime/providers/logging/loggingProvider");
exports.command = `delete <${constants_1.CommandArgId}>`;
exports.describe = 'Delete a mabl environment';
exports.builder = (yargs) => {
    yargs.positional(constants_1.CommandArgId, {
        describe: 'Environment id to delete',
        type: 'string',
    });
};
exports.handler = (0, cliUtil_1.failWrapper)(deleteEnvironment);
async function deleteEnvironment(parsed) {
    let environment;
    try {
        const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
        environment = await apiClient.deleteEnvironment(parsed.id);
        loggingProvider_1.logger.info(chalk_1.default.green(`Environment ${chalk_1.default.bold(environment.id ?? '')} DELETED`));
    }
    catch (error) {
        throw new Error(`Error deleting environment: ${error}`);
    }
    return environment.id;
}
