"use strict";
/**
 * Default Command Handler
 *
 * Sets or clears the default profile.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleResetDefault = exports.handleDefault = void 0;
const ui_1 = require("../../utils/ui");
const errors_1 = require("../../errors");
const exit_codes_1 = require("../../errors/exit-codes");
const types_1 = require("./types");
const config_loader_facade_1 = require("../../config/config-loader-facade");
/**
 * Handle the default command (set default profile)
 */
async function handleDefault(ctx, args) {
    await (0, ui_1.initUI)();
    const parsed = (0, types_1.parseArgs)(args);
    const { profileName } = parsed;
    (0, types_1.rejectUnsupportedAuthOptions)(parsed, {
        usage: 'ccs auth default <profile>',
    });
    if (!profileName) {
        console.log((0, ui_1.fail)('Profile name is required'));
        console.log('');
        console.log(`Usage: ${(0, ui_1.color)('ccs auth default <profile>', 'command')}`);
        (0, errors_1.exitWithError)('Profile name is required', exit_codes_1.ExitCode.PROFILE_ERROR);
    }
    try {
        // Use unified or legacy based on config mode
        if ((0, config_loader_facade_1.isUnifiedMode)()) {
            ctx.registry.setDefaultUnified(profileName);
        }
        else {
            ctx.registry.setDefaultProfile(profileName);
        }
        console.log((0, ui_1.ok)(`Default profile set: ${profileName}`));
        console.log('');
        console.log('Now you can use:');
        console.log(`  ${(0, ui_1.color)('ccs "your prompt"', 'command')}  ${(0, ui_1.dim)(`# Uses ${profileName} profile`)}`);
        console.log('');
    }
    catch (error) {
        (0, errors_1.exitWithError)(error.message, exit_codes_1.ExitCode.PROFILE_ERROR);
    }
}
exports.handleDefault = handleDefault;
/**
 * Handle the reset-default command (clear the custom default)
 */
async function handleResetDefault(ctx, args = []) {
    await (0, ui_1.initUI)();
    const parsed = (0, types_1.parseArgs)(args);
    (0, types_1.rejectUnsupportedAuthOptions)(parsed, {
        usage: 'ccs auth reset-default',
    });
    try {
        // Use unified or legacy based on config mode
        if ((0, config_loader_facade_1.isUnifiedMode)()) {
            ctx.registry.clearDefaultUnified();
        }
        else {
            ctx.registry.clearDefaultProfile();
        }
        console.log((0, ui_1.ok)('Default profile cleared'));
        console.log('');
        console.log('CCS will now use the original behavior:');
        console.log(`  ${(0, ui_1.dim)('# Uses your primary Claude account')}`);
        console.log(`  ${(0, ui_1.color)('ccs "your prompt"', 'command')}`);
        console.log('');
    }
    catch (error) {
        console.log((0, ui_1.fail)(error.message));
        process.exit(1);
    }
}
exports.handleResetDefault = handleResetDefault;
//# sourceMappingURL=default-command.js.map