class EarningsSummaryModel {
  EarningsSummaryModel({
    required this.totalEarningsByWeek,
    required this.totalEarningsByMonth,
    required this.totalWorkedHoursByWeek,
    required this.totalWorkedHoursByMonth,
    required this.payoutByWeek,
    required this.payoutByMonth,
    required this.startDatePeriod,
    required this.endDatePeriod,
    required this.maxEarningInPeriod,
    required this.minEarningInPeriod,
  });

  //TODO: Additional fields that are used in the Earnings History screen are for now returning default values.
  factory EarningsSummaryModel.fromJson(Map<String, dynamic> json) {
    final time = DateTime.now();
    return EarningsSummaryModel(
      totalEarningsByWeek: (json['weekly_earnings'] as num?)?.toDouble() ?? 0,
      totalEarningsByMonth: (json['monthly_earnings'] as num?)?.toDouble() ?? 0,
      totalWorkedHoursByWeek: (json['weekly_hours'] as num?)?.toDouble() ?? 0,
      totalWorkedHoursByMonth: (json['monthly_hours'] as num?)?.toDouble() ?? 0,
      payoutByWeek: 0,
      payoutByMonth: 0,
      startDatePeriod: DateTime(time.year, time.month),
      endDatePeriod: DateTime(time.year, time.month, 28),
      maxEarningInPeriod: 0,
      minEarningInPeriod: 0,
    );
  }

  final double totalEarningsByWeek;
  final double totalEarningsByMonth;
  final double totalWorkedHoursByWeek;
  final double totalWorkedHoursByMonth;
  final double payoutByWeek;
  final double payoutByMonth;
  final DateTime? startDatePeriod;
  final DateTime? endDatePeriod;
  final int maxEarningInPeriod;
  final int minEarningInPeriod;

  EarningsSummaryModel copyWith({
    double? totalEarningsByWeek,
    double? totalEarningsByMonth,
    double? totalWorkedHoursByWeek,
    double? totalWorkedHoursByMonth,
    double? payoutByWeek,
    double? payoutByMonth,
    DateTime? startDatePeriod,
    DateTime? endDatePeriod,
    int? maxEarningInPeriod,
    int? minEarningInPeriod,
  }) {
    return EarningsSummaryModel(
      totalEarningsByWeek: totalEarningsByWeek ?? this.totalEarningsByWeek,
      totalEarningsByMonth: totalEarningsByMonth ?? this.totalEarningsByMonth,
      totalWorkedHoursByWeek:
          totalWorkedHoursByWeek ?? this.totalWorkedHoursByWeek,
      totalWorkedHoursByMonth:
          totalWorkedHoursByMonth ?? this.totalWorkedHoursByMonth,
      payoutByWeek: payoutByWeek ?? this.payoutByWeek,
      payoutByMonth: payoutByMonth ?? this.payoutByMonth,
      startDatePeriod: startDatePeriod,
      endDatePeriod: endDatePeriod,
      maxEarningInPeriod: maxEarningInPeriod ?? this.maxEarningInPeriod,
      minEarningInPeriod: minEarningInPeriod ?? this.minEarningInPeriod,
    );
  }
}
