"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteCommand = void 0;
const logger_1 = __importDefault(require("../logger"));
const telemetry_1 = __importDefault(require("../telemetry"));
const util_1 = require("../util");
async function handleEvalDelete(evalId, envPath) {
    try {
        await (0, util_1.deleteEval)(evalId);
        logger_1.default.info(`Evaluation with ID ${evalId} has been successfully deleted.`);
    }
    catch (error) {
        logger_1.default.error(`Could not delete evaluation with ID ${evalId}:\n${error}`);
        process.exit(1);
    }
}
function deleteCommand(program) {
    const deleteCommand = program
        .command('delete <id>')
        .description('Delete various resources')
        .option('--env-path <path>', 'Path to the environment file')
        .action(async (id, cmdObj) => {
        (0, util_1.setupEnv)(cmdObj.envPath);
        telemetry_1.default.maybeShowNotice();
        telemetry_1.default.record('command_used', {
            name: 'delete',
        });
        const evl = await (0, util_1.getEvalFromId)(id);
        if (evl) {
            return handleEvalDelete(id, cmdObj.envPath);
        }
        logger_1.default.error(`No resource found with ID ${id}`);
    });
    deleteCommand
        .command('eval <id>')
        .description('Delete an evaluation by ID.')
        .option('--env-path <path>', 'Path to the environment file')
        .action(async (evalId, cmdObj) => {
        (0, util_1.setupEnv)(cmdObj.envPath);
        telemetry_1.default.maybeShowNotice();
        telemetry_1.default.record('command_used', {
            name: 'delete eval',
            evalId: evalId,
        });
        await telemetry_1.default.send();
        handleEvalDelete(evalId, cmdObj.envPath);
    });
}
exports.deleteCommand = deleteCommand;
//# sourceMappingURL=delete.js.map