class EmployeeDetailsModel {
  final String id;
  final String firstName;
  final String lastName;
  final String? middleName;
  final String? email;
  final String gender;
  final DateTime? birthDate;
  final DateTime? joiningDate;
  final String? permanentAddress;
  final String? currentAddress;
  final String phoneNumber;
  final String? emergencyPhoneNumber;
  final String? emergencyContactPerson;
  final String? aadharNumber;
  final bool isActive;
  final String? panNumber;
  final String? photo;
  final String? applicationUserId;
  final String jobRoleId;
  final bool isSystem;
  final String jobRole;

  EmployeeDetailsModel({
    required this.id,
    required this.firstName,
    required this.lastName,
    this.middleName,
    this.email,
    required this.gender,
    this.birthDate,
    this.joiningDate,
    this.permanentAddress,
    this.currentAddress,
    required this.phoneNumber,
    this.emergencyPhoneNumber,
    this.emergencyContactPerson,
    this.aadharNumber,
    required this.isActive,
    this.panNumber,
    this.photo,
    this.applicationUserId,
    required this.jobRoleId,
    required this.isSystem,
    required this.jobRole,
  });

  factory EmployeeDetailsModel.fromJson(Map<String, dynamic> json) {
    return EmployeeDetailsModel(
      id: json['id'],
      firstName: json['firstName'],
      lastName: json['lastName'],
      middleName: json['middleName'],
      email: json['email'],
      gender: json['gender'],
      birthDate: _parseDate(json['birthDate']),
      joiningDate: _parseDate(json['joiningDate']),
      permanentAddress: json['permanentAddress'],
      currentAddress: json['currentAddress'],
      phoneNumber: json['phoneNumber'],
      emergencyPhoneNumber: json['emergencyPhoneNumber'],
      emergencyContactPerson: json['emergencyContactPerson'],
      aadharNumber: json['aadharNumber'],
      isActive: json['isActive'],
      panNumber: json['panNumber'],
      photo: json['photo'],
      applicationUserId: json['applicationUserId'],
      jobRoleId: json['jobRoleId'],
      isSystem: json['isSystem'],
      jobRole: json['jobRole'],
    );
  }

  static DateTime? _parseDate(String? dateStr) {
    if (dateStr == null || dateStr == "0001-01-01T00:00:00") {
      return null;
    }
    return DateTime.tryParse(dateStr);
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'firstName': firstName,
      'lastName': lastName,
      'middleName': middleName,
      'email': email,
      'gender': gender,
      'birthDate': birthDate?.toIso8601String(),
      'joiningDate': joiningDate?.toIso8601String(),
      'permanentAddress': permanentAddress,
      'currentAddress': currentAddress,
      'phoneNumber': phoneNumber,
      'emergencyPhoneNumber': emergencyPhoneNumber,
      'emergencyContactPerson': emergencyContactPerson,
      'aadharNumber': aadharNumber,
      'isActive': isActive,
      'panNumber': panNumber,
      'photo': photo,
      'applicationUserId': applicationUserId,
      'jobRoleId': jobRoleId,
      'isSystem': isSystem,
      'jobRole': jobRole,
    };
  }
}
