import { Controller, Logger } from '@nestjs/common';
import { EventPattern, Payload } from '@nestjs/microservices';

interface MpcKeygenCompletedEvent {
  eventId: string;
  eventType: string;
  occurredAt: string;
  payload: {
    userId: string;
    deviceId: string;
    publicKey: string;
    keyType: string;
  };
}

/**
 * Kafka 事件消费者
 * 监听来自其他服务的事件
 */
@Controller()
export class EventConsumerController {
  private readonly logger = new Logger(EventConsumerController.name);

  /**
   * 处理 MPC 密钥生成完成事件
   * 从 mpc-service 接收公钥，派生钱包地址
   */
  @EventPattern('mpc.keygen.completed')
  async handleMpcKeygenCompleted(@Payload() event: MpcKeygenCompletedEvent): Promise<void> {
    this.logger.log(`Received MPC keygen completed event: ${event.eventId}`);
    this.logger.debug(`User: ${event.payload.userId}, PublicKey: ${event.payload.publicKey}`);

    // TODO: 调用 AddressDerivationService 派生地址
    // 这将在应用层实现
  }
}
