"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 cli_app_service_1 = require("../../lib/services/cli-app.service");
const resolve_cluster_1 = require("../../lib/resolve-cluster");
class AppStart extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(AppStart);
        const spinner = (0, ora_1.default)(`Starting "${args.name}"...`).start();
        try {
            const { id: clusterId } = await (0, resolve_cluster_1.resolveCluster)(flags.cluster);
            const service = await cli_app_service_1.CliAppService.create(clusterId);
            const app = await service.getAppByName(args.name);
            await service.start(app.id);
            spinner.succeed(`"${args.name}" started`);
            console.log(chalk_1.default.dim('\n  Pods are coming up. Check status with:'));
            console.log(chalk_1.default.cyan(`  flui app status ${args.name}\n`));
        }
        catch (error) {
            spinner.fail('Failed to start application');
            console.log(chalk_1.default.red(`\n  Error: ${error.message}\n`));
            this.exit(1);
        }
    }
}
AppStart.description = 'Start a stopped application';
AppStart.examples = ['<%= config.bin %> <%= command.id %> my-api'];
AppStart.args = {
    name: core_1.Args.string({
        description: 'Application name or slug',
        required: true,
    }),
};
AppStart.flags = {
    cluster: core_1.Flags.string({
        char: 'c',
        description: 'Cluster name or ID (default: auto-detect when only one cluster exists)',
    }),
};
exports.default = AppStart;
