"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const backup_client_1 = require("../../../lib/backup-client");
const prompts_1 = require("../../../lib/prompts");
const context_banner_1 = require("../../../lib/context-banner");
class BackupPolicyDelete extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(BackupPolicyDelete);
        (0, context_banner_1.printContextBanner)();
        const client = backup_client_1.BackupClient.fromConfig();
        if (!flags.yes) {
            const ok = await (0, prompts_1.confirmPrompt)(chalk_1.default.yellow(`Delete policy ${args.id}? Existing backups are kept.`), false);
            if (!ok) {
                this.log(chalk_1.default.green('Cancelled'));
                return;
            }
        }
        const spinner = (0, ora_1.default)('Deleting...').start();
        try {
            await client.deletePolicy(args.id);
            spinner.succeed(`Deleted ${args.id}`);
        }
        catch (err) {
            spinner.fail(`Delete failed: ${err.message}`);
            this.exit(1);
        }
    }
}
BackupPolicyDelete.description = 'Delete a backup policy (existing artifacts are retained)';
BackupPolicyDelete.args = {
    id: core_1.Args.string({ required: true }),
};
BackupPolicyDelete.flags = {
    yes: core_1.Flags.boolean({ char: 'y', default: false }),
};
exports.default = BackupPolicyDelete;
