"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleApiRemoveCommand = void 0;
const services_1 = require("../../api/services");
const ui_1 = require("../../utils/ui");
const prompt_1 = require("../../utils/prompt");
const shared_1 = require("./shared");
async function handleApiRemoveCommand(args) {
    await (0, ui_1.initUI)();
    const parsedArgs = (0, shared_1.parseApiCommandArgs)(args);
    (0, shared_1.exitOnApiCommandErrors)(parsedArgs.errors);
    const apis = (0, services_1.getApiProfileNames)();
    if (apis.length === 0) {
        console.log((0, ui_1.warn)('No API profiles to remove'));
        process.exit(0);
    }
    let name = parsedArgs.name;
    if (!name) {
        console.log((0, ui_1.header)('Remove API Profile'));
        console.log('');
        console.log('Available APIs:');
        apis.forEach((api, index) => console.log(`  ${index + 1}. ${api}`));
        console.log('');
        name = await prompt_1.InteractivePrompt.input('API name to remove', {
            validate: (value) => {
                if (!value)
                    return 'API name is required';
                if (!apis.includes(value))
                    return `API '${value}' not found`;
                return null;
            },
        });
    }
    if (!apis.includes(name)) {
        console.log((0, ui_1.fail)(`API '${name}' not found`));
        console.log('');
        console.log('Available APIs:');
        apis.forEach((api) => console.log(`  - ${api}`));
        process.exit(1);
    }
    console.log('');
    console.log(`API '${(0, ui_1.color)(name, 'command')}' will be removed.`);
    console.log(`  Settings: ~/.ccs/${name}.settings.json`);
    if ((0, services_1.isUsingUnifiedConfig)()) {
        console.log('  Config: ~/.ccs/config.yaml');
    }
    console.log('');
    const confirmed = parsedArgs.yes ||
        (await prompt_1.InteractivePrompt.confirm('Delete this API profile?', { default: false }));
    if (!confirmed) {
        console.log((0, ui_1.info)('Cancelled'));
        process.exit(0);
    }
    const result = (0, services_1.removeApiProfile)(name);
    if (!result.success) {
        console.log((0, ui_1.fail)(`Failed to remove API profile: ${result.error}`));
        process.exit(1);
    }
    console.log((0, ui_1.ok)(`API profile removed: ${name}`));
    console.log('');
}
exports.handleApiRemoveCommand = handleApiRemoveCommand;
//# sourceMappingURL=remove-command.js.map