import 'package:equatable/equatable.dart';

/// 账户状态枚举
enum ContributionAccountStatus {
  /// 正常 - 账户存在且有算力数据
  active,
  /// 未激活 - 用户存在但暂无任何算力
  inactive,
  /// 用户不存在
  userNotFound,
}

class Contribution extends Equatable {
  /// 账户状态
  final ContributionAccountStatus status;
  /// 状态说明
  final String message;
  /// 账户序号
  final String accountSequence;
  /// 个人算力
  final String personalContribution;
  /// 团队层级算力
  final String teamLevelContribution;
  /// 团队奖励算力
  final String teamBonusContribution;
  /// 总算力
  final String totalContribution;
  /// 是否已参与
  final bool hasAdopted;
  /// 引荐参与用户数
  final int directReferralAdoptedCount;
  /// 已解锁层级深度
  final int unlockedLevelDepth;
  /// 已解锁奖励档位数
  final int unlockedBonusTiers;
  /// 是否已完成计算
  final bool isCalculated;
  /// 最后计算时间
  final DateTime? lastCalculatedAt;

  const Contribution({
    required this.status,
    required this.message,
    required this.accountSequence,
    required this.personalContribution,
    required this.teamLevelContribution,
    required this.teamBonusContribution,
    required this.totalContribution,
    required this.hasAdopted,
    required this.directReferralAdoptedCount,
    required this.unlockedLevelDepth,
    required this.unlockedBonusTiers,
    required this.isCalculated,
    this.lastCalculatedAt,
  });

  /// 团队总贡献值 (层级 + 奖励)
  String get teamContribution {
    final teamLevel = double.tryParse(teamLevelContribution) ?? 0;
    final teamBonus = double.tryParse(teamBonusContribution) ?? 0;
    return (teamLevel + teamBonus).toString();
  }

  /// 是否处于活跃状态
  bool get isActive => status == ContributionAccountStatus.active;

  @override
  List<Object?> get props => [
        status,
        message,
        accountSequence,
        personalContribution,
        teamLevelContribution,
        teamBonusContribution,
        totalContribution,
        hasAdopted,
        directReferralAdoptedCount,
        unlockedLevelDepth,
        unlockedBonusTiers,
        isCalculated,
        lastCalculatedAt,
      ];
}
