"use strict";
/**
 * Config Auth Commands (Facade)
 *
 * CLI interface for managing dashboard authentication.
 * Commands: setup, show, disable
 *
 * Implementation follows auth-commands.ts pattern.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleConfigAuthCommand = void 0;
const ui_1 = require("../../utils/ui");
const named_command_router_1 = require("../named-command-router");
// Import command handlers
const setup_command_1 = require("./setup-command");
const show_command_1 = require("./show-command");
const disable_command_1 = require("./disable-command");
async function ensureNoConfigAuthArgs(command, args) {
    if (args.length === 0) {
        return;
    }
    await (0, ui_1.initUI)();
    console.log((0, ui_1.fail)(`Unexpected arguments for "config auth ${command}": ${args.join(' ')}`));
    console.log('');
    console.log('Run for help:');
    console.log(`  ${(0, ui_1.color)('ccs config auth --help', 'command')}`);
    process.exit(1);
}
function createZeroArgConfigAuthRoute(name, handler, aliases) {
    return {
        name,
        aliases,
        handle: async (args) => {
            await ensureNoConfigAuthArgs(name, args);
            await handler();
        },
    };
}
const CONFIG_AUTH_ROUTES = [
    createZeroArgConfigAuthRoute('setup', setup_command_1.handleSetup),
    createZeroArgConfigAuthRoute('show', show_command_1.handleShow, ['status']),
    createZeroArgConfigAuthRoute('disable', disable_command_1.handleDisable),
];
/**
 * Show help for config auth commands
 */
async function showHelp() {
    await (0, ui_1.initUI)();
    console.log('');
    console.log((0, ui_1.header)('Dashboard Auth Management'));
    console.log('');
    console.log((0, ui_1.subheader)('Usage'));
    console.log(`  ${(0, ui_1.color)('ccs config auth', 'command')} <command>`);
    console.log('');
    console.log((0, ui_1.subheader)('Commands'));
    console.log(`  ${(0, ui_1.color)('setup', 'command')}               Configure username and password`);
    console.log(`  ${(0, ui_1.color)('show', 'command')}                Display current auth status`);
    console.log(`  ${(0, ui_1.color)('disable', 'command')}             Disable authentication`);
    console.log('');
    console.log((0, ui_1.subheader)('Examples'));
    console.log(`  ${(0, ui_1.dim)('# Interactive setup wizard')}`);
    console.log(`  ${(0, ui_1.color)('ccs config auth setup', 'command')}`);
    console.log('');
    console.log(`  ${(0, ui_1.dim)('# Check current status')}`);
    console.log(`  ${(0, ui_1.color)('ccs config auth show', 'command')}`);
    console.log('');
    console.log(`  ${(0, ui_1.dim)('# Disable authentication')}`);
    console.log(`  ${(0, ui_1.color)('ccs config auth disable', 'command')}`);
    console.log('');
    console.log((0, ui_1.subheader)('Environment Variables'));
    console.log('  These override config.yaml values:');
    console.log(`  ${(0, ui_1.color)('CCS_DASHBOARD_AUTH_ENABLED', 'command')}     Enable/disable (true/false)`);
    console.log(`  ${(0, ui_1.color)('CCS_DASHBOARD_USERNAME', 'command')}         Username`);
    console.log(`  ${(0, ui_1.color)('CCS_DASHBOARD_PASSWORD_HASH', 'command')}    Bcrypt hash`);
    console.log('');
    console.log((0, ui_1.subheader)('Documentation'));
    console.log('  https://ccs.kaitran.ca/features/dashboard-auth');
    console.log('');
}
/**
 * Route config auth command to appropriate handler
 */
async function handleConfigAuthCommand(args) {
    await (0, named_command_router_1.dispatchNamedCommand)({
        args,
        routes: CONFIG_AUTH_ROUTES,
        onHelp: showHelp,
        allowEmptyHelp: true,
        onUnknown: async (command) => {
            await (0, ui_1.initUI)();
            console.log((0, ui_1.fail)(`Unknown command: ${command}`));
            console.log('');
            console.log('Run for help:');
            console.log(`  ${(0, ui_1.color)('ccs config auth --help', 'command')}`);
            process.exit(1);
        },
    });
}
exports.handleConfigAuthCommand = handleConfigAuthCommand;
//# sourceMappingURL=index.js.map