"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 = `terminate <${constants_1.CommandArgId}>`;
exports.describe = 'Sends a shutdown signal to a specific Link Agent.';
exports.builder = (yargs) => {
    yargs.positional(constants_1.CommandArgId, {
        describe: 'id of the link agent to terminate',
        type: 'string',
    });
};
exports.handler = (0, cliUtil_1.failWrapper)(terminateLinkAgent);
async function terminateLinkAgent(parsed) {
    try {
        const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
        const linkAgentId = parsed[constants_1.CommandArgId];
        await apiClient.terminateLinkAgent(linkAgentId);
        loggingProvider_1.logger.info(chalk_1.default.green(`Link agent ${chalk_1.default.bold(linkAgentId)} terminated`));
        return linkAgentId;
    }
    catch (error) {
        throw new Error(`Error terminating link agent: ${error}`);
    }
}
