/**
 * olam mcp status — Show detailed status of all MCP credentials.
 */
import pc from 'picocolors';
import { printError, printHeader } from '../../output.js';
import { getMcpAuthClient } from './client.js';
function formatExpiry(expiresAt) {
    if (!expiresAt)
        return '—';
    const ms = expiresAt - Date.now();
    if (ms <= 0)
        return pc.red('expired');
    const hours = ms / (1000 * 60 * 60);
    if (hours < 1)
        return pc.yellow(`${Math.ceil(ms / 60000)}m`);
    return `${hours.toFixed(1)}h`;
}
export function registerMcpStatus(cmd) {
    cmd
        .command('status')
        .description('Show status of all MCP credentials')
        .action(async () => {
        const client = getMcpAuthClient();
        let data;
        try {
            data = await client.status();
        }
        catch (err) {
            printError(`Could not reach mcp-auth service: ${err instanceof Error ? err.message : 'unknown error'}`);
            process.exitCode = 1;
            return;
        }
        const mcps = data.mcps ?? [];
        printHeader(`MCP Credentials (${mcps.length})`);
        if (mcps.length === 0) {
            console.log(pc.dim('No credentials registered.'));
            return;
        }
        for (const m of mcps) {
            const stateColor = !m.validated ? pc.yellow : m.expired ? pc.red : pc.green;
            const stateLabel = !m.validated ? 'unvalidated' : m.expired ? 'expired' : 'active';
            console.log(`\n  ${pc.cyan(m.service)} ${stateColor(`[${stateLabel}]`)}`);
            console.log(`    label:      ${m.label}`);
            console.log(`    type:       ${m.type}`);
            if (m.envName)
                console.log(`    env var:    ${m.envName}`);
            if (m.importedFrom)
                console.log(`    imported:   ${m.importedFrom}`);
            if (m.type === 'oauth')
                console.log(`    expires in: ${formatExpiry(m.expiresAt)}`);
            if (m.lastUsed)
                console.log(`    last used:  ${new Date(m.lastUsed).toLocaleString()}`);
        }
        console.log('');
    });
}
//# sourceMappingURL=status.js.map