"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 context_banner_1 = require("../../../lib/context-banner");
class BackupDestinationTest extends core_1.Command {
    async run() {
        const { args } = await this.parse(BackupDestinationTest);
        (0, context_banner_1.printContextBanner)();
        const client = backup_client_1.BackupClient.fromConfig();
        const spinner = (0, ora_1.default)(`Testing destination ${args.id}...`).start();
        try {
            const res = await client.testDestination(args.id);
            if (res.healthy) {
                spinner.succeed('Destination reachable');
            }
            else {
                const suffix = res.error ? ` — ${res.error}` : '';
                spinner.fail(`Test failed${suffix}`);
                this.exit(1);
            }
        }
        catch (err) {
            spinner.fail(`Test failed: ${err.message}`);
            this.exit(1);
        }
        void chalk_1.default;
    }
}
BackupDestinationTest.description = 'Test connectivity to a backup destination (S3 PUT/GET/DELETE round-trip)';
BackupDestinationTest.args = {
    id: core_1.Args.string({ required: true, description: 'Destination ID' }),
};
exports.default = BackupDestinationTest;
