/**
 * 用户详情页面响应 DTO
 */

// ============================================================================
// 用户完整信息
// ============================================================================

/**
 * 推荐信息
 */
export class ReferralInfoDto {
  myReferralCode!: string;
  usedReferralCode!: string | null;
  referrerId!: string | null;
  referrerSequence!: string | null;
  referrerNickname!: string | null;
  ancestorPath!: string | null;
  depth!: number;
  directReferralCount!: number;
  activeDirectCount!: number;
}

/**
 * 用户完整详情响应
 */
export class UserFullDetailDto {
  accountId!: string;
  accountSequence!: string;
  avatar!: string | null;
  nickname!: string | null;
  phoneNumberMasked!: string | null;
  status!: 'active' | 'frozen' | 'deactivated';
  kycStatus!: string;
  isOnline!: boolean;
  registeredAt!: string;
  lastActiveAt!: string | null;

  // 认种统计
  personalAdoptions!: number;
  teamAddresses!: number;
  teamAdoptions!: number;
  provincialAdoptions!: {
    count: number;
    percentage: number;
  };
  cityAdoptions!: {
    count: number;
    percentage: number;
  };

  // 预种统计
  selfPrePlantingPortions!: number;
  teamPrePlantingPortions!: number;

  // 排名
  ranking!: number | null;

  // 推荐信息
  referralInfo!: ReferralInfoDto;
}

// ============================================================================
// 推荐关系树
// ============================================================================

/**
 * 推荐关系节点
 */
export class ReferralNodeDto {
  accountSequence!: string;
  userId!: string;
  nickname!: string | null;
  avatar!: string | null;
  personalAdoptions!: number;
  teamAdoptions!: number; // 团队认种量
  selfPrePlantingPortions!: number; // 个人预种份数
  teamPrePlantingPortions!: number; // 团队预种份数
  depth!: number;
  directReferralCount!: number;
  isCurrentUser?: boolean;
}

/**
 * 推荐关系树响应
 */
export class ReferralTreeDto {
  currentUser!: ReferralNodeDto;
  ancestors!: ReferralNodeDto[]; // 向上的推荐人链
  directReferrals!: ReferralNodeDto[]; // 直推用户列表
}

// ============================================================================
// 认种分类账
// ============================================================================

/**
 * 认种汇总
 */
export class PlantingSummaryDto {
  totalOrders!: number;
  totalTreeCount!: number;
  totalAmount!: string;
  effectiveTreeCount!: number;
  pendingTreeCount!: number;
  firstPlantingAt!: string | null;
  lastPlantingAt!: string | null;
}

/**
 * 认种分类账项
 */
export class PlantingLedgerItemDto {
  orderId!: string;
  orderNo!: string;
  treeCount!: number;
  totalAmount!: string;
  status!: string;
  selectedProvince!: string | null;
  selectedCity!: string | null;
  createdAt!: string;
  paidAt!: string | null;
  fundAllocatedAt!: string | null;
  miningEnabledAt!: string | null;
}

/**
 * 认种分类账响应
 */
export class PlantingLedgerResponseDto {
  summary!: PlantingSummaryDto;
  items!: PlantingLedgerItemDto[];
  total!: number;
  page!: number;
  pageSize!: number;
  totalPages!: number;
}

// ============================================================================
// 钱包分类账
// ============================================================================

/**
 * 钱包汇总
 */
export class WalletSummaryDto {
  // USDT
  usdtAvailable!: string;
  usdtFrozen!: string;
  // DST
  dstAvailable!: string;
  dstFrozen!: string;
  // BNB
  bnbAvailable!: string;
  bnbFrozen!: string;
  // OG
  ogAvailable!: string;
  ogFrozen!: string;
  // RWAD
  rwadAvailable!: string;
  rwadFrozen!: string;
  // 算力
  hashpower!: string;
  // 收益
  pendingUsdt!: string;
  pendingHashpower!: string;
  settleableUsdt!: string;
  settleableHashpower!: string;
  settledTotalUsdt!: string;
  settledTotalHashpower!: string;
  expiredTotalUsdt!: string;
  expiredTotalHashpower!: string;
}

/**
 * 钱包分类账项
 */
export class WalletLedgerItemDto {
  entryId!: string;
  entryType!: string;
  assetType!: string;
  amount!: string;
  balanceAfter!: string | null;
  refOrderId!: string | null;
  refTxHash!: string | null;
  memo!: string | null;
  createdAt!: string;
}

/**
 * 钱包分类账响应
 */
export class WalletLedgerResponseDto {
  summary!: WalletSummaryDto;
  items!: WalletLedgerItemDto[];
  total!: number;
  page!: number;
  pageSize!: number;
  totalPages!: number;
}

// ============================================================================
// 授权信息
// ============================================================================

/**
 * 授权角色
 */
export class AuthorizationRoleDto {
  id!: string;
  roleType!: string;
  regionCode!: string;
  regionName!: string;
  displayTitle!: string;
  status!: string;
  benefitActive!: boolean;
  benefitActivatedAt!: string | null;
  authorizedAt!: string | null;
  authorizedBy!: string | null;
  initialTargetTreeCount!: number;
  monthlyTargetType!: string;
  lastAssessmentMonth!: string | null;
  monthlyTreesAdded!: number;
  officePhotoUrls!: string[];
  createdAt!: string;
}

/**
 * 月度考核
 */
export class MonthlyAssessmentDto {
  id!: string;
  authorizationId!: string;
  roleType!: string;
  regionCode!: string;
  assessmentMonth!: string;
  monthIndex!: number;
  monthlyTarget!: number;
  monthlyCompleted!: number;
  cumulativeTarget!: number;
  cumulativeCompleted!: number;
  result!: string;
  rankingInRegion!: number | null;
  isFirstPlace!: boolean;
  isBypassed!: boolean;
  completedAt!: string | null;
  assessedAt!: string | null;
}

/**
 * 系统账户流水项
 */
export class SystemAccountLedgerItemDto {
  ledgerId!: string;
  accountId!: string;
  accountType!: string;
  entryType!: string;
  amount!: string;
  balanceAfter!: string;
  sourceOrderId!: string | null;
  sourceRewardId!: string | null;
  txHash!: string | null;
  memo!: string | null;
  createdAt!: string;
}

/**
 * [2026-01-08] 权益考核记录
 * 独立于火柴人排名（MonthlyAssessment），专门记录权益有效性考核历史
 */
export class BenefitAssessmentDto {
  id!: string;
  authorizationId!: string;
  roleType!: string;
  regionCode!: string;
  regionName!: string;
  assessmentMonth!: string;
  monthIndex!: number;
  monthlyTarget!: number;
  cumulativeTarget!: number;
  treesCompleted!: number;
  treesRequired!: number;
  benefitActionTaken!: string; // ACTIVATED, RENEWED, DEACTIVATED, NO_CHANGE
  previousBenefitStatus!: boolean;
  newBenefitStatus!: boolean;
  newValidUntil!: string | null;
  result!: string;
  remarks!: string | null;
  assessedAt!: string;
  createdAt!: string;
}

/**
 * 授权详情响应
 */
export class AuthorizationDetailResponseDto {
  roles!: AuthorizationRoleDto[];
  assessments!: MonthlyAssessmentDto[];
  benefitAssessments!: BenefitAssessmentDto[]; // [2026-01-08] 新增：权益考核记录
  systemAccountLedger!: SystemAccountLedgerItemDto[];
}
