"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.showUnknownApiCommand = exports.showApiCommandHelp = void 0;
const services_1 = require("../../api/services");
const ui_1 = require("../../utils/ui");
const shared_1 = require("./shared");
function renderPresetHelpLine(preset, idWidth) {
    const presetId = (0, shared_1.sanitizeHelpText)(preset.id) || 'unknown';
    const paddedId = presetId.padEnd(idWidth);
    const presetName = (0, shared_1.sanitizeHelpText)(preset.name) || 'Unknown preset';
    const presetDescription = (0, shared_1.sanitizeHelpText)(preset.description) || 'No description';
    return `  ${(0, ui_1.color)(paddedId, 'command')} ${presetName} - ${presetDescription}`;
}
async function showApiCommandHelp(writeLine = console.log) {
    await (0, ui_1.initUI)();
    const presetIds = (0, services_1.getPresetIds)()
        .map((id) => (0, shared_1.sanitizeHelpText)(id))
        .filter(Boolean);
    const cliproxyProviderIds = (0, services_1.listCliproxyBridgeProviders)().map((provider) => provider.provider);
    const presetAliases = (0, services_1.getPresetAliases)();
    const presetIdWidth = Math.max(0, ...presetIds.map((id) => id.length)) + 2;
    writeLine((0, ui_1.header)('CCS API Management'));
    writeLine('');
    writeLine((0, ui_1.subheader)('Usage'));
    writeLine(`  ${(0, ui_1.color)('ccs api', 'command')} <command> [options]`);
    writeLine('');
    writeLine((0, ui_1.subheader)('Commands'));
    writeLine(`  ${(0, ui_1.color)('create [name]', 'command')}    Create new API profile (interactive)`);
    writeLine(`  ${(0, ui_1.color)('list', 'command')}             List all API profiles`);
    writeLine(`  ${(0, ui_1.color)('discover', 'command')}         Discover orphan *.settings.json and register`);
    writeLine(`  ${(0, ui_1.color)('copy <src> <dest>', 'command')} Duplicate API profile settings + config`);
    writeLine(`  ${(0, ui_1.color)('export <name>', 'command')}    Export profile bundle for cross-device transfer`);
    writeLine(`  ${(0, ui_1.color)('import <file>', 'command')}    Import profile bundle and register profile`);
    writeLine(`  ${(0, ui_1.color)('remove <name>', 'command')}    Remove an API profile`);
    writeLine('');
    writeLine((0, ui_1.subheader)('Options'));
    writeLine(`  ${(0, ui_1.color)('--preset <id>', 'command')}        Use provider preset (${presetIds.join(', ')})`);
    writeLine(`  ${(0, ui_1.color)('--cliproxy-provider <id>', 'command')} Use routed CLIProxy provider (${cliproxyProviderIds.join(', ')})`);
    writeLine(`  ${(0, ui_1.color)('--base-url <url>', 'command')}     API base URL (create)`);
    writeLine(`  ${(0, ui_1.color)('--api-key <key>', 'command')}      API key (create)`);
    writeLine(`  ${(0, ui_1.color)('--model <model>', 'command')}      Default model (create)`);
    writeLine(`  ${(0, ui_1.color)('--extra-models <list>', 'command')} Comma-separated extra models to expose alongside --model`);
    writeLine(`  ${(0, ui_1.color)('--1m / --no-1m', 'command')}         Write or clear [1m] on compatible Claude mappings`);
    writeLine(`  ${(0, ui_1.color)('--target <cli>', 'command')}       Default target: claude or droid (create)`);
    writeLine(`  ${(0, ui_1.color)('--register', 'command')}           Register discovered orphan settings`);
    writeLine(`  ${(0, ui_1.color)('--json', 'command')}               JSON output for discover command`);
    writeLine(`  ${(0, ui_1.color)('--out <file>', 'command')}         Export bundle output path`);
    writeLine(`  ${(0, ui_1.color)('--include-secrets', 'command')}    Include token in export bundle`);
    writeLine(`  ${(0, ui_1.color)('--name <name>', 'command')}        Override profile name during import`);
    writeLine(`  ${(0, ui_1.color)('--force', 'command')}              Overwrite existing or bypass validation (create/discover/copy/import)`);
    writeLine(`  ${(0, ui_1.color)('--yes, -y', 'command')}            Skip confirmation prompts`);
    writeLine('');
    writeLine((0, ui_1.subheader)('Provider Presets'));
    services_1.PROVIDER_PRESETS.forEach((preset) => writeLine(renderPresetHelpLine(preset, presetIdWidth)));
    Object.entries(presetAliases).forEach(([alias, canonical]) => {
        const safeAlias = (0, shared_1.sanitizeHelpText)(alias);
        const safeCanonical = (0, shared_1.sanitizeHelpText)(canonical);
        writeLine(`  ${(0, ui_1.dim)(`Legacy alias: --preset ${safeAlias} (auto-mapped to ${safeCanonical})`)}`);
    });
    writeLine('');
    writeLine((0, ui_1.subheader)('Examples'));
    writeLine(`  ${(0, ui_1.dim)('# Interactive wizard')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Quick setup with preset')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --preset anthropic', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --preset anthropic --1m', 'command')} ${(0, ui_1.dim)('# explicit Claude [1m] opt-in')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --preset openrouter', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --preset alibaba-coding-plan', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --preset alibaba', 'command')} ${(0, ui_1.dim)('# alias')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create hf-router --preset hf', 'command')} ${(0, ui_1.dim)('# defaults to droid for generic chat completions')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --preset glm', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Expose multiple models from one provider endpoint')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create dashscope --base-url https://... --api-key sk-xxx --model qwen3-coder-plus --extra-models glm-4.6,kimi-k2', 'command')}`);
    writeLine('');
    writeLine((0, ui_1.subheader)('Claude Long Context'));
    writeLine(`  ${(0, ui_1.dim)('Plain Claude model IDs stay on standard context by default.')}`);
    writeLine(`  ${(0, ui_1.dim)('Use --1m during create to append [1m] to compatible Claude mappings, or --no-1m to force plain IDs.')}`);
    writeLine(`  ${(0, ui_1.dim)('CCS controls only the saved [1m] suffix. Provider pricing/entitlement stay upstream, and some accounts can still return 429 for long-context requests.')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Create routed profile from existing CLIProxy provider config')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create --cliproxy-provider gemini', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create gemini-droid --cliproxy-provider gemini --target droid', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create codex-api --cliproxy-provider codex', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs codex-api --target codex', 'command')} ${(0, ui_1.dim)('# runtime-only native Codex launch')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Create with name')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create myapi', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api create mydroid --preset glm --target droid', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Remove API profile')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api remove myapi', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Discover and register orphan settings files')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api discover', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api discover --register', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Duplicate an existing API profile')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api copy glm glm-backup', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Export and import across devices')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api export glm --out ./glm.ccs-profile.json', 'command')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api import ./glm.ccs-profile.json', 'command')}`);
    writeLine('');
    writeLine(`  ${(0, ui_1.dim)('# Show all API profiles')}`);
    writeLine(`  ${(0, ui_1.color)('ccs api list', 'command')}`);
    writeLine('');
}
exports.showApiCommandHelp = showApiCommandHelp;
async function showUnknownApiCommand(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 api --help', 'command')}`);
    process.exit(1);
}
exports.showUnknownApiCommand = showUnknownApiCommand;
//# sourceMappingURL=help.js.map