export interface UserOverview {
  accountSequence: number;
  accountId?: string;
  nickname: string;
  phone: string;
  phoneNumberMasked?: string;
  avatar?: string | null;
  hasAdopted: boolean;
  totalContribution: string;
  effectiveContribution: string;
  miningBalance: string;
  tradingBalance: string;
  frozenBalance: string;
  // 从 admin-web 复用的字段
  personalAdoptions?: number;
  personalAdoptionOrders?: number;  // 个人认种订单数
  teamAdoptions?: number;
  teamAdoptionOrders?: number;      // 团队认种订单数
  teamAddresses?: number;
  provincialAdoptions?: {
    count: number;
    percentage: number;
  };
  cityAdoptions?: {
    count: number;
    percentage: number;
  };
  referrerId?: string | null;
  ranking?: number | null;
  status?: 'active' | 'frozen' | 'deactivated';
  isOnline?: boolean;
  createdAt: string;
}

export interface UserDetail extends UserOverview {
  referrerAccountSequence: string | null;
  referrerNickname?: string | null;
  directReferralCount: number;
  directReferralAdoptedCount: number;
  teamSize: number;
  teamAdoptedCount: number;
  contributions: ContributionBreakdown;
  // 从 admin-web 复用的字段
  kycStatus?: string;
  registeredAt?: string;
  lastActiveAt?: string;
  referralInfo?: {
    referrerSequence?: string;
    referrerNickname?: string;
    usedReferralCode?: string;
    depth?: number;
    directReferralCount?: number;
  };
}

export interface ContributionBreakdown {
  personal: string;
  teamLevel: string;
  teamBonus: string;
  total: string;
  // 解锁状态
  hasAdopted: boolean;
  directReferralCount: number;
  unlockedLevelDepth: number;  // 0, 5, 10, 15
  unlockedBonusTiers: number;  // 0, 1, 2, 3
}

export interface ContributionRecord {
  id: string;
  sourceType: string;  // PERSONAL, TEAM_LEVEL, TEAM_BONUS
  sourceAccountSequence: string;
  sourceUserInfo?: {
    nickname: string | null;
    phone: string;
  } | null;
  treeCount: number;
  baseContribution: string;
  distributionRate: string;
  levelDepth: number | null;
  bonusTier: number | null;
  amount: string;
  effectiveDate: string;
  expireDate: string;
  isExpired: boolean;
  createdAt: string;
}

export interface MiningRecord {
  id: string;
  accountSequence: number;
  distributionMinute: string;
  contributionRatio: string;
  shareAmount: string;
  priceSnapshot: string;
  createdAt: string;
}

export interface TradeOrder {
  id: string;
  accountSequence: number;
  orderType: 'BUY' | 'SELL';
  status: 'PENDING' | 'PARTIAL' | 'FILLED' | 'CANCELLED';
  price: string;
  quantity: string;
  filledQuantity: string;
  createdAt: string;
  updatedAt: string;
}

// 引荐关系节点
export interface ReferralNode {
  accountSequence: string;
  nickname: string | null;
  avatar?: string | null;
  personalAdoptions: number;
  teamAdoptions: number;
  directReferralCount: number;
  isOnline?: boolean;
}

// 引荐关系树
export interface ReferralTreeData {
  currentUser: ReferralNode;
  ancestors: ReferralNode[];
  directReferrals: ReferralNode[];
}

// 认种订单
export interface PlantingOrder {
  orderId: string;
  orderNo: string;
  treeCount: number;
  totalAmount: string;
  selectedProvince?: string;
  selectedCity?: string;
  status: string;
  createdAt: string;
  paidAt?: string;
}

// 认种汇总
export interface PlantingSummary {
  totalOrders: number;
  totalTreeCount: number;
  totalAmount: string;
  effectiveTreeCount: number;
  firstPlantingAt?: string;
  lastPlantingAt?: string;
}

// 认种分类账响应
export interface PlantingLedgerResponse {
  summary: PlantingSummary;
  items: PlantingOrder[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
}

// 钱包流水
export interface WalletLedgerItem {
  entryId: string;
  entryType: string;
  assetType: string;
  amount: string;
  balanceAfter: string;
  refOrderId?: string;
  refTxHash?: string;
  memo?: string;
  createdAt: string;
}

// 钱包汇总
export interface WalletSummary {
  usdtAvailable: string;
  usdtFrozen: string;
  pendingUsdt: string;
  settleableUsdt: string;
  settledTotalUsdt: string;
  expiredTotalUsdt: string;
}

// 钱包分类账响应
export interface WalletLedgerResponse {
  summary: WalletSummary;
  items: WalletLedgerItem[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
}
