"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");
const PROVIDERS = [
    'hetzner_object_storage',
    'scaleway_object_storage',
    'minio',
    'generic_s3',
];
const ENCRYPTION_MODES = ['flui_managed', 'byo_passphrase', 'none'];
class BackupDestinationCreate extends core_1.Command {
    async run() {
        const { flags } = await this.parse(BackupDestinationCreate);
        (0, context_banner_1.printContextBanner)();
        const client = backup_client_1.BackupClient.fromConfig();
        const spinner = (0, ora_1.default)('Creating backup destination...').start();
        try {
            const dest = await client.createDestination({
                name: flags.name,
                provider: flags.provider,
                endpoint: flags.endpoint,
                region: flags.region,
                bucket: flags.bucket,
                pathPrefix: flags.prefix,
                accessKey: flags['access-key'],
                secretKey: flags['secret-key'],
                encryptionMode: flags['encryption-mode'],
                encryptionPassphrase: flags['encryption-passphrase'],
                forcePathStyle: flags['force-path-style'],
                useSse: flags['use-sse'],
                usableForEtcdL1: flags['usable-for-etcd-l1'],
                costPerGbMonthCents: flags['cost-per-gb-month-cents'],
            });
            spinner.succeed(`Created destination ${chalk_1.default.cyan(dest.id)}`);
            this.log('');
            this.log(`   ${chalk_1.default.bold('Name:')}     ${dest.name}`);
            this.log(`   ${chalk_1.default.bold('Provider:')} ${dest.provider}`);
            this.log(`   ${chalk_1.default.bold('Bucket:')}   ${dest.bucket}`);
            this.log('');
            this.log(chalk_1.default.dim(`   Test with: flui backup destination test ${dest.id}\n`));
        }
        catch (err) {
            spinner.fail(`Create failed: ${err.message}`);
            this.exit(1);
        }
    }
}
BackupDestinationCreate.description = 'Create a backup destination (S3-compatible storage target for Velero)';
BackupDestinationCreate.examples = [
    '<%= config.bin %> <%= command.id %> --name my-s3 --provider hetzner_object_storage --endpoint https://fsn1.your-objectstorage.com --region fsn1 --bucket flui-backups --access-key AK --secret-key SK',
    '<%= config.bin %> <%= command.id %> --name scw --provider scaleway_object_storage --endpoint https://s3.fr-par.scw.cloud --region fr-par --bucket flui-bkp --access-key AK --secret-key SK',
];
BackupDestinationCreate.flags = {
    name: core_1.Flags.string({
        required: true,
        description: 'Display name (≤120 chars)',
    }),
    provider: core_1.Flags.string({
        required: true,
        options: [...PROVIDERS],
        description: 'Storage backend provider',
    }),
    endpoint: core_1.Flags.string({
        required: true,
        description: 'S3 endpoint URL (e.g. https://s3.fr-par.scw.cloud)',
    }),
    region: core_1.Flags.string({ required: true }),
    bucket: core_1.Flags.string({ required: true }),
    'access-key': core_1.Flags.string({ required: true }),
    'secret-key': core_1.Flags.string({ required: true }),
    prefix: core_1.Flags.string({
        description: 'Optional path prefix inside the bucket',
    }),
    'encryption-mode': core_1.Flags.string({
        options: [...ENCRYPTION_MODES],
        description: 'Encryption mode (default: flui_managed)',
    }),
    'encryption-passphrase': core_1.Flags.string({
        description: 'Required when --encryption-mode=byo_passphrase',
    }),
    'force-path-style': core_1.Flags.boolean({
        description: 'Force path-style S3 URLs (needed for MinIO/some providers)',
    }),
    'use-sse': core_1.Flags.boolean({
        description: 'Use server-side encryption (SSE-S3) at the provider',
    }),
    'usable-for-etcd-l1': core_1.Flags.boolean({
        description: 'Allow this destination to receive L1 etcd snapshots',
    }),
    'cost-per-gb-month-cents': core_1.Flags.integer({
        description: 'Provider cost in cents/GB·month (used for billing estimate)',
        min: 0,
    }),
};
exports.default = BackupDestinationCreate;
