import { ApiProperty } from '@nestjs/swagger';

/**
 * 账户状态枚举
 */
export enum ContributionAccountStatus {
  /** 正常 - 账户存在且有算力数据（自己认种或有下级认种产生的待解锁算力） */
  ACTIVE = 'ACTIVE',
  /** 未激活 - 用户存在但自己和团队均未认种，暂无任何算力 */
  INACTIVE = 'INACTIVE',
  /** 用户不存在 - 系统中不存在该账户序号 */
  USER_NOT_FOUND = 'USER_NOT_FOUND',
}

export class ContributionAccountResponse {
  @ApiProperty({
    description: '账户状态',
    enum: ContributionAccountStatus,
    example: ContributionAccountStatus.ACTIVE,
  })
  status: ContributionAccountStatus;

  @ApiProperty({
    description: '状态说明',
    example: '账户正常',
  })
  message: string;

  @ApiProperty({ description: '账户序号' })
  accountSequence: string;

  @ApiProperty({ description: '个人算力' })
  personalContribution: string;

  @ApiProperty({ description: '团队层级算力' })
  teamLevelContribution: string;

  @ApiProperty({ description: '团队奖励算力' })
  teamBonusContribution: string;

  @ApiProperty({ description: '总算力' })
  totalContribution: string;

  @ApiProperty({ description: '是否已认种' })
  hasAdopted: boolean;

  @ApiProperty({ description: '直推认种用户数' })
  directReferralAdoptedCount: number;

  @ApiProperty({ description: '已解锁层级深度' })
  unlockedLevelDepth: number;

  @ApiProperty({ description: '已解锁奖励档位数' })
  unlockedBonusTiers: number;

  @ApiProperty({ description: '是否已完成计算' })
  isCalculated: boolean;

  @ApiProperty({ description: '最后计算时间', nullable: true })
  lastCalculatedAt: Date | null;
}

export class ContributionRecordResponse {
  @ApiProperty({ description: '记录ID' })
  id: string;

  @ApiProperty({ description: '来源类型', enum: ['PERSONAL', 'TEAM_LEVEL', 'TEAM_BONUS'] })
  sourceType: string;

  @ApiProperty({ description: '来源认种ID' })
  sourceAdoptionId: string;

  @ApiProperty({ description: '来源账户序号', nullable: true })
  sourceAccountSequence: string | null;

  @ApiProperty({ description: '树数量' })
  treeCount: number;

  @ApiProperty({ description: '基础算力' })
  baseContribution: string;

  @ApiProperty({ description: '分配比例' })
  distributionRate: string;

  @ApiProperty({ description: '层级深度', nullable: true })
  levelDepth: number | null;

  @ApiProperty({ description: '奖励档位', nullable: true })
  bonusTier: number | null;

  @ApiProperty({ description: '最终算力' })
  finalContribution: string;

  @ApiProperty({ description: '生效日期' })
  effectiveDate: Date;

  @ApiProperty({ description: '过期日期' })
  expireDate: Date;

  @ApiProperty({ description: '是否已过期' })
  isExpired: boolean;

  @ApiProperty({ description: '创建时间' })
  createdAt: Date;
}

export class ContributionRecordsResponse {
  @ApiProperty({ type: [ContributionRecordResponse] })
  data: ContributionRecordResponse[];

  @ApiProperty({ description: '总记录数' })
  total: number;

  @ApiProperty({ description: '当前页码' })
  page: number;

  @ApiProperty({ description: '每页大小' })
  pageSize: number;
}

export class ActiveContributionResponse {
  @ApiProperty({ description: '个人算力' })
  personal: string;

  @ApiProperty({ description: '团队层级算力' })
  teamLevel: string;

  @ApiProperty({ description: '团队奖励算力' })
  teamBonus: string;

  @ApiProperty({ description: '总算力' })
  total: string;
}
