import { UserId } from '@/domain/value-objects';

export interface MpcKeyShareData {
  userId: bigint;
  publicKey: string;
  partyIndex: number;
  threshold: number;
  totalParties: number;
  encryptedShareData: string;
}

export interface MpcKeyShare {
  shareId: bigint;
  userId: bigint;
  publicKey: string;
  partyIndex: number;
  threshold: number;
  totalParties: number;
  encryptedShareData: string;
  status: string;
  createdAt: Date;
  rotatedAt: Date | null;
}

export const MPC_KEY_SHARE_REPOSITORY = Symbol('MPC_KEY_SHARE_REPOSITORY');

export interface MpcKeyShareRepository {
  /**
   * 保存服务端 MPC 分片
   */
  saveServerShare(data: MpcKeyShareData): Promise<MpcKeyShare>;

  /**
   * 根据用户ID查找分片
   */
  findByUserId(userId: UserId): Promise<MpcKeyShare | null>;

  /**
   * 根据公钥查找分片
   */
  findByPublicKey(publicKey: string): Promise<MpcKeyShare | null>;

  /**
   * 更新分片状态 (用于密钥轮换)
   */
  updateStatus(shareId: bigint, status: string): Promise<void>;

  /**
   * 轮换分片 (更新分片数据)
   */
  rotateShare(shareId: bigint, newEncryptedData: string): Promise<void>;
}
