class RegularizationLogModel {
  final String id;
  final String employeeId;
  final String name;
  final String role;
  final DateTime? checkIn;
  final DateTime? checkOut;
  final int activity;
  final String firstName;
  final String lastName;

  RegularizationLogModel({
    required this.id,
    required this.employeeId,
    required this.name,
    required this.role,
    this.checkIn,
    this.checkOut,
    required this.activity,
    required this.firstName,
    required this.lastName,
  });

  factory RegularizationLogModel.fromJson(Map<String, dynamic> json) {
    return RegularizationLogModel(
      id: json['id']?.toString() ?? '',
      employeeId: json['employeeId']?.toString() ?? '',
      name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(),
      role: json['jobRoleName'] ?? '',
      checkIn: json['checkInTime'] != null
          ? DateTime.tryParse(json['checkInTime'].toString())
          : null,
      checkOut: json['checkOutTime'] != null
          ? DateTime.tryParse(json['checkOutTime'].toString())
          : null,
      activity: json['activity'] ?? 0,
      firstName: json['firstName'] ?? '',
      lastName: json['lastName'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'employeeId': employeeId,
      'firstName': name.split(' ').first,
      'lastName': name.split(' ').length > 1 ? name.split(' ').last : '',
      'jobRoleName': role,
      'checkInTime': checkIn?.toIso8601String(),
      'checkOutTime': checkOut?.toIso8601String(),
      'activity': activity,
    };
  }
}
