import 'package:equatable/equatable.dart';

/// 贡献值来源类型
enum ContributionSourceType {
  personal,   // 个人 - 参与
  teamLevel,  // 团队层级 - 引荐/间推奖励
  teamBonus,  // 团队奖励 - 额外奖励
}

/// 贡献值记录
class ContributionRecord extends Equatable {
  final String id;
  final ContributionSourceType sourceType;
  final String sourceAdoptionId;
  final String? sourceAccountSequence;
  final int treeCount;
  final String baseContribution;
  final String distributionRate;
  final int? levelDepth;
  final int? bonusTier;
  final String finalContribution;
  final DateTime effectiveDate;
  final DateTime expireDate;
  final bool isExpired;
  final DateTime createdAt;

  const ContributionRecord({
    required this.id,
    required this.sourceType,
    required this.sourceAdoptionId,
    this.sourceAccountSequence,
    required this.treeCount,
    required this.baseContribution,
    required this.distributionRate,
    this.levelDepth,
    this.bonusTier,
    required this.finalContribution,
    required this.effectiveDate,
    required this.expireDate,
    required this.isExpired,
    required this.createdAt,
  });

  /// 获取记录的显示标题
  String get displayTitle {
    switch (sourceType) {
      case ContributionSourceType.personal:
        return '参与';
      case ContributionSourceType.teamLevel:
        if (levelDepth == 1) {
          return '引荐奖励';
        }
        return '同伴奖励($levelDepth级)';
      case ContributionSourceType.teamBonus:
        return '同伴额外奖励';
    }
  }

  @override
  List<Object?> get props => [
        id,
        sourceType,
        sourceAdoptionId,
        sourceAccountSequence,
        treeCount,
        baseContribution,
        distributionRate,
        levelDepth,
        bonusTier,
        finalContribution,
        effectiveDate,
        expireDate,
        isExpired,
        createdAt,
      ];
}

/// 贡献值记录分页响应
class ContributionRecordsPage extends Equatable {
  final List<ContributionRecord> data;
  final int total;
  final int page;
  final int pageSize;

  const ContributionRecordsPage({
    required this.data,
    required this.total,
    required this.page,
    required this.pageSize,
  });

  bool get hasMore => page * pageSize < total;

  @override
  List<Object?> get props => [data, total, page, pageSize];
}
