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

export function registerIdentityCommand(program: Command): void {
  program
    .command('identity')
    .description('Show current identity information')
    .action(async () => {
      try {
        printHeader('Clawiverse Identity');

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

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

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

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

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