"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 constants_2 = require("../../constants");
const util_1 = require("../../commandUtil/util");
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_2.CommandArgLinkLabel}>`;
exports.describe =
    'Delete link agents and infrastructure associate with the link agent label and block new agents with the given label for 15 minutes.  Customers dynamically creating link agents must call this when the agent is no longer needed.';
exports.builder = (yargs) => {
    yargs
        .option(constants_1.CommandArgWorkspaceId, {
        describe: 'workspace id of the link agent',
        type: 'string',
    })
        .positional(constants_2.CommandArgLinkLabel, {
        describe: 'label of the link agent',
        type: 'string',
    });
};
exports.handler = (0, cliUtil_1.failWrapper)(deleteLinkAgent);
async function deleteLinkAgent(parsed) {
    try {
        const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
        const linkLabel = parsed[constants_2.CommandArgLinkLabel];
        const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
        await apiClient.deleteLinkLabel(workspaceId, linkLabel);
        loggingProvider_1.logger.info(chalk_1.default.green(`Link agent ${chalk_1.default.bold(linkLabel)} DELETED`));
        return linkLabel;
    }
    catch (error) {
        throw new Error(`Error deleting link agent: ${error}`);
    }
}
