"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 BackupJobList extends core_1.Command {
    async run() {
        const { flags } = await this.parse(BackupJobList);
        (0, context_banner_1.printContextBanner)();
        const client = backup_client_1.BackupClient.fromConfig();
        const items = await client.listJobsForCluster(flags.cluster);
        if (flags.json) {
            this.log(JSON.stringify(items, null, 2));
            return;
        }
        if (items.length === 0) {
            this.log(chalk_1.default.yellow('\n   No jobs.\n'));
            return;
        }
        this.log('');
        for (const j of items) {
            this.log(`   ${chalk_1.default.cyan(j.id)}  ${j.status}  policy=${j.policyId}` +
                (j.startedAt ? ` started=${j.startedAt}` : '') +
                (j.completedAt ? ` done=${j.completedAt}` : ''));
        }
        this.log('');
    }
}
BackupJobList.description = 'List backup jobs for a cluster';
BackupJobList.flags = {
    cluster: core_1.Flags.string({ required: true, description: 'Cluster ID' }),
    json: core_1.Flags.boolean({ default: false }),
};
exports.default = BackupJobList;
