"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.statusCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const helpers_1 = require("./helpers");
const context_1 = require("./context");
exports.statusCommand = {
    command: 'status',
    describe: 'Show project setup state: framework, SDK, API key, auth (JSON-friendly)',
    builder: (yargs) => yargs.options({
        'install-dir': {
            describe: 'project directory to inspect',
            type: 'string',
        },
    }),
    handler: (argv) => {
        void (async () => {
            const installDir = argv['install-dir'] ?? process.cwd();
            const { resolveMode } = await import('../lib/mode-config.js');
            const { jsonOutput } = resolveMode({
                json: argv.json,
                human: argv.human,
                isTTY: Boolean(process.stdout.isTTY),
            });
            try {
                const { runStatus } = await import('../lib/agent-ops.js');
                const result = await runStatus(installDir);
                if (jsonOutput) {
                    process.stdout.write(JSON.stringify(result) + '\n');
                }
                else {
                    const check = (v) => (v ? chalk_1.default.green('✔') : chalk_1.default.dim('·'));
                    const ui = (0, helpers_1.getUI)();
                    ui.log.info(`${check(result.framework.integration !== null)} Framework: ${result.framework.name ?? chalk_1.default.dim('none detected')}`);
                    ui.log.info(`${check(result.amplitudeInstalled.confidence !== 'none')} Amplitude SDK: ${result.amplitudeInstalled.reason ?? chalk_1.default.dim('not installed')}`);
                    ui.log.info(`${check(result.apiKey.configured)} API key: ${result.apiKey.configured
                        ? `stored in ${result.apiKey.source}`
                        : chalk_1.default.dim('not set')}`);
                    ui.log.info(`${check(result.auth.loggedIn)} Logged in: ${result.auth.loggedIn
                        ? `${result.auth.email} (${result.auth.zone})`
                        : chalk_1.default.dim(`run \`${context_1.CLI_INVOCATION} login\``)}`);
                }
                process.exit(0);
            }
            catch (e) {
                const message = e instanceof Error ? e.message : String(e);
                if (jsonOutput) {
                    process.stdout.write(JSON.stringify({ error: message }) + '\n');
                }
                else {
                    (0, helpers_1.getUI)().log.error(`Status failed: ${message}`);
                }
                process.exit(helpers_1.ExitCode.GENERAL_ERROR);
            }
        })();
    },
};
