"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 BackupPolicyList extends core_1.Command {
    async run() {
        const { flags } = await this.parse(BackupPolicyList);
        (0, context_banner_1.printContextBanner)();
        const client = backup_client_1.BackupClient.fromConfig();
        const items = flags.cluster
            ? await client.listPoliciesForCluster(flags.cluster)
            : await client.listPolicies();
        if (flags.json) {
            this.log(JSON.stringify(items, null, 2));
            return;
        }
        if (items.length === 0) {
            this.log(chalk_1.default.yellow('\n   No backup policies.\n'));
            return;
        }
        this.log('');
        for (const p of items) {
            this.log(`   ${chalk_1.default.cyan(p.id)}  ${chalk_1.default.bold(p.name)}  ${p.profile}/${p.scope}  cluster=${p.clusterId}` +
                (p.schedule ? ` cron=${p.schedule}` : '') +
                (p.enabled === false ? chalk_1.default.dim(' [disabled]') : ''));
        }
        this.log('');
    }
}
BackupPolicyList.description = 'List backup policies';
BackupPolicyList.flags = {
    cluster: core_1.Flags.string({ description: 'Filter by cluster ID' }),
    json: core_1.Flags.boolean({ default: false }),
};
exports.default = BackupPolicyList;
