import { Command } from 'commander';
import { getIdentity, getAgentCard, getBootstrapPeers } from '../config.js';
import { error, printHeader, printKeyValue, printSection } from '../ui.js';

export function registerStatusCommand(program: Command): void {
  program
    .command('status')
    .description('Show current status')
    .action(async () => {
      try {
        printHeader('Clawiverse Status');

        const identity = getIdentity();
        const card = getAgentCard();
        const bootstrapPeers = getBootstrapPeers();

        if (!identity) {
          error('No identity configured. Run "hw1 init" first.');
          process.exit(1);
        }

        printSection('Identity');
        printKeyValue('DID', identity.did);
        printKeyValue('Public Key', identity.publicKey.substring(0, 16) + '...');

        if (card) {
          printSection('Agent Card');
          printKeyValue('Name', card.name);
          printKeyValue('Description', card.description);
          printKeyValue('Capabilities', card.capabilities.join(', ') || 'None');
        }

        printSection('Network');
        printKeyValue(
          'Bootstrap Peers',
          bootstrapPeers.length > 0 ? bootstrapPeers.join(', ') : 'None configured'
        );

        console.log();
      } catch (err) {
        error(`Failed to show status: ${(err as Error).message}`);
        process.exit(1);
      }
    });
}
