import '../../domain/entities/contribution_stats.dart';

class ContributionStatsModel extends ContributionStats {
  const ContributionStatsModel({
    required super.totalUsers,
    required super.totalAccounts,
    required super.accountsWithContribution,
    required super.totalAdoptions,
    required super.totalContribution,
    required super.personalContribution,
    required super.teamLevelContribution,
    required super.teamBonusContribution,
  });

  factory ContributionStatsModel.fromJson(Map<String, dynamic> json) {
    final contributionByType = json['contributionByType'] as Map<String, dynamic>? ?? {};

    return ContributionStatsModel(
      totalUsers: json['totalUsers'] ?? 0,
      totalAccounts: json['totalAccounts'] ?? 0,
      accountsWithContribution: json['accountsWithContribution'] ?? 0,
      totalAdoptions: json['totalAdoptions'] ?? 0,
      totalContribution: json['totalContribution']?.toString() ?? '0',
      personalContribution: contributionByType['personal']?.toString() ?? '0',
      teamLevelContribution: contributionByType['teamLevel']?.toString() ?? '0',
      teamBonusContribution: contributionByType['teamBonus']?.toString() ?? '0',
    );
  }
}
