/**
 * 贡献值分配完成事件
 * 来自 contribution-service
 */
export interface ContributionDistributionCompletedEvent {
  eventType: 'ContributionDistributionCompleted';
  eventId: string;
  timestamp: string;
  payload: ContributionDistributionPayload;
}

export interface ContributionDistributionPayload {
  // 认种信息
  adoptionId: string;
  adopterAccountSequence: string;
  treeCount: number;
  adoptionDate: string;

  // 用户贡献值分配
  userContributions: UserContributionItem[];

  // 系统账户分配
  systemContributions: SystemContributionItem[];

  // 未分配（归总部）
  unallocatedToHeadquarters: UnallocatedContributionItem[];
}

export interface UserContributionItem {
  accountSequence: string;
  contributionType: 'PERSONAL' | 'TEAM_LEVEL' | 'TEAM_BONUS';
  amount: string;
  levelDepth?: number; // 1-15 for TEAM_LEVEL
  bonusTier?: number; // 1-3 for TEAM_BONUS
  effectiveDate: string;
  expireDate: string;
  sourceAdoptionId: string;
  sourceAccountSequence: string;
}

export interface SystemContributionItem {
  accountType: 'OPERATION' | 'PROVINCE' | 'CITY' | 'HEADQUARTERS';
  amount: string;
  provinceCode?: string;
  cityCode?: string;
  neverExpires: boolean;
}

export interface UnallocatedContributionItem {
  reason: string;
  amount: string;
  wouldBeAccountSequence?: string;
  levelDepth?: number;
  bonusTier?: number;
}

/**
 * 奖励补发事件
 * 来自 contribution-service，当用户解锁新的奖励档位时触发
 */
export interface BonusClaimedEvent {
  eventType: 'BonusClaimed';
  eventId: string;
  timestamp: string;
  payload: BonusClaimedPayload;
}

export interface BonusClaimedPayload {
  accountSequence: string;
  bonusTier: number;
  claimedCount: number;
  userContributions: BonusClaimedContributionItem[];
}

export interface BonusClaimedContributionItem {
  accountSequence: string;
  contributionType: 'TEAM_BONUS';
  amount: string;
  bonusTier: number;
  effectiveDate: string;
  expireDate: string;
  sourceAdoptionId: string;
  sourceAccountSequence: string;
  isBackfill: boolean;
}

/**
 * 用户注册事件
 * 来自 auth-service
 */
export interface UserRegisteredEvent {
  eventType: 'UserRegistered';
  eventId: string;
  timestamp: string;
  payload: {
    accountSequence: string;
    phone: string;
    referrerAccountSequence: string | null;
    registeredAt: string;
    source: 'LEGACY_MIGRATION' | 'NEW_REGISTRATION';
  };
}
