"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 backup_client_1 = require("../../../lib/backup-client");
const context_banner_1 = require("../../../lib/context-banner");
class BackupDestinationList extends core_1.Command {
    async run() {
        const { flags } = await this.parse(BackupDestinationList);
        (0, context_banner_1.printContextBanner)();
        const client = backup_client_1.BackupClient.fromConfig();
        const items = await client.listDestinations();
        if (flags.json) {
            this.log(JSON.stringify(items, null, 2));
            return;
        }
        if (items.length === 0) {
            this.log(chalk_1.default.yellow('\n   No backup destinations configured.\n'));
            this.log(chalk_1.default.dim('   Create one with: flui backup destination create --help\n'));
            return;
        }
        this.log('');
        for (const d of items) {
            const usage = d.usageBytes
                ? ` · ${(d.usageBytes / 1024 ** 3).toFixed(2)} GB`
                : '';
            const health = d.health ? chalk_1.default.dim(` [${d.health}]`) : '';
            this.log(`   ${chalk_1.default.cyan(d.id)}  ${chalk_1.default.bold(d.name)}  ${d.provider}  ` +
                `${d.region}/${d.bucket}${usage}${health}`);
        }
        this.log('');
    }
}
BackupDestinationList.description = 'List backup destinations configured in the API';
BackupDestinationList.examples = ['<%= config.bin %> <%= command.id %>'];
BackupDestinationList.flags = {
    json: core_1.Flags.boolean({ description: 'Output as JSON', default: false }),
};
exports.default = BackupDestinationList;
