"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleApiListCommand = void 0;
const services_1 = require("../../api/services");
const ui_1 = require("../../utils/ui");
const shared_1 = require("./shared");
async function handleApiListCommand(args = []) {
    await (0, ui_1.initUI)();
    const syntax = (0, shared_1.collectUnexpectedApiArgs)(args, {
        maxPositionals: 0,
    });
    if (syntax.errors.length > 0) {
        syntax.errors.forEach((errorMessage) => console.log((0, ui_1.fail)(errorMessage)));
        process.exit(1);
    }
    console.log((0, ui_1.header)('CCS API Profiles'));
    console.log('');
    const { profiles, variants } = (0, services_1.listApiProfiles)();
    if (profiles.length === 0) {
        console.log((0, ui_1.warn)('No API profiles configured'));
        console.log('');
        console.log('To create an API profile:');
        console.log(`  ${(0, ui_1.color)('ccs api create', 'command')}`);
        console.log('');
        return;
    }
    const rows = profiles.map((profile) => {
        const status = profile.isConfigured ? (0, ui_1.color)('[OK]', 'success') : (0, ui_1.color)('[!]', 'warning');
        return [profile.name, profile.target, profile.settingsPath, status];
    });
    console.log((0, ui_1.table)(rows, {
        head: ['API', 'Target', (0, services_1.isUsingUnifiedConfig)() ? 'Config' : 'Settings File', 'Status'],
        colWidths: (0, services_1.isUsingUnifiedConfig)() ? [15, 10, 20, 10] : [15, 10, 35, 10],
    }));
    console.log('');
    if (variants.length > 0) {
        console.log((0, ui_1.subheader)('CLIProxy Variants'));
        console.log((0, ui_1.table)(variants.map((variant) => [
            variant.name,
            variant.provider,
            variant.target,
            variant.settings,
        ]), {
            head: ['Variant', 'Provider', 'Target', 'Settings'],
            colWidths: [15, 12, 10, 28],
        }));
        console.log('');
    }
    console.log((0, ui_1.dim)(`Total: ${profiles.length} API profile(s)`));
    console.log('');
}
exports.handleApiListCommand = handleApiListCommand;
//# sourceMappingURL=list-command.js.map