class RewardDto {
  final String id;
  final DateTime date;
  final double amount;
  final String? reason;
  final String? note;
  final String employeeId;

  RewardDto({
    required this.id,
    required this.date,
    required this.amount,
    this.reason,
    this.note,
    required this.employeeId,
  });

  factory RewardDto.fromJson(Map<String, dynamic> json) {
    return RewardDto(
      id: json['id']?.toString() ?? '',
      date:
          json['date'] != null ? DateTime.parse(json['date']) : DateTime.now(),
      amount: (json['amount'] as num?)?.toDouble() ?? 0.0,
      reason: json['reason'],
      note: json['note'],
      employeeId: json['employeeId']?.toString() ?? '',
    );
  }
}

class RewardListResponseDto {
  final List<RewardDto> items;

  RewardListResponseDto({required this.items});

  factory RewardListResponseDto.fromJson(Map<String, dynamic> json) {
    final data = json['data'];
    if (data == null || data is! Map<String, dynamic>) {
      return RewardListResponseDto(items: []);
    }
    final itemsJson = data['items'] as List? ?? [];
    return RewardListResponseDto(
      items: itemsJson.map((e) => RewardDto.fromJson(e)).toList(),
    );
  }
}
