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 bool? isActive;
  final bool? isRootUser;
  final bool? isSystem;
  final String? jobRole;
  final String? jobRoleId;
  final String? photo;
  final String? applicationUserId;
  final bool? hasApplicationAccess;
  final String? organizationId;
  final String? aadharNumber;
  final String? panNumber;

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

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

  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,
      'isActive': isActive,
      'isRootUser': isRootUser,
      'isSystem': isSystem,
      'jobRole': jobRole,
      'jobRoleId': jobRoleId,
      'photo': photo,
      'applicationUserId': applicationUserId,
      'hasApplicationAccess': hasApplicationAccess,
      'organizationId': organizationId,
      'aadharNumber': aadharNumber,
      'panNumber': panNumber,
    };
  }

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