"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 cli_app_service_1 = require("../../../lib/services/cli-app.service");
const resolve_cluster_1 = require("../../../lib/resolve-cluster");
const prompts_1 = require("../../../lib/prompts");
class AppSnapshotDelete extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(AppSnapshotDelete);
        if (!flags.force) {
            const ok = await (0, prompts_1.confirmPrompt)(`Delete snapshot "${args.snapshotId}" of app "${args.name}"?`);
            if (!ok) {
                console.log(chalk_1.default.dim('  Aborted.'));
                return;
            }
        }
        const spinner = (0, ora_1.default)(`Deleting snapshot ${args.snapshotId}...`).start();
        try {
            const { id: clusterId } = await (0, resolve_cluster_1.resolveCluster)(flags.cluster);
            const service = await cli_app_service_1.CliAppService.create(clusterId);
            const app = await service.getAppByName(args.name);
            await service.deleteAppSnapshot(app.id, args.snapshotId);
            spinner.succeed(`Deleted snapshot ${args.snapshotId}`);
        }
        catch (error) {
            spinner.fail('Snapshot deletion failed');
            const msg = error.response?.data?.message ?? error.message ?? String(error);
            console.log(chalk_1.default.red(`\n  Error: ${msg}\n`));
            this.exit(1);
        }
    }
}
AppSnapshotDelete.description = 'Delete a volume snapshot of an application.';
AppSnapshotDelete.examples = [
    '<%= config.bin %> <%= command.id %> my-app my-app-snap-20260510-abcdef',
    '<%= config.bin %> <%= command.id %> my-app my-app-snap-... --force',
];
AppSnapshotDelete.args = {
    name: core_1.Args.string({
        description: 'Application name or slug',
        required: true,
    }),
    snapshotId: core_1.Args.string({
        description: 'Snapshot id (from `flui app snapshot list`)',
        required: true,
    }),
};
AppSnapshotDelete.flags = {
    cluster: core_1.Flags.string({
        char: 'c',
        description: 'Cluster name or ID (default: auto-detect)',
    }),
    force: core_1.Flags.boolean({
        char: 'f',
        description: 'Skip confirmation',
    }),
};
exports.default = AppSnapshotDelete;
