import 'dart:convert';

import 'package:mohem_flutter_app/classes/consts.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MemberInformationListModel {
  String? aCTUALTERMINATIONDATE;
  String? aSSIGNMENTENDDATE;
  int? aSSIGNMENTID;
  String? aSSIGNMENTNUMBER;
  String? aSSIGNMENTSTARTDATE;
  int? aSSIGNMENTSTATUSTYPEID;
  String? aSSIGNMENTTYPE;
  int? bUSINESSGROUPID;
  String? bUSINESSGROUPNAME;
  String? businessCardQR;
  String? cURRENTEMPLOYEEFLAG;
  String? eMPLOYEEDISPLAYNAME;
  String? eMPLOYEEDISPLAYNAMEAr;
  String? eMPLOYEEDISPLAYNAMEEn;
  String? eMPLOYEEEMAILADDRESS;
  String? eMPLOYEEIMAGE;
  String? eMPLOYEEMOBILENUMBER;
  String? eMPLOYEENAME;
  String? eMPLOYEENAMEAr;
  String? eMPLOYEENAMEEn;
  String? eMPLOYEENUMBER;
  String? eMPLOYEEWORKNUMBER;
  String? eMPLOYMENTCATEGORY;
  String? eMPLOYMENTCATEGORYMEANING;
  String? employeeQR;
  String? fREQUENCY;
  String? fREQUENCYMEANING;
  int? fROMROWNUM;
  int? gRADEID;
  String? gRADENAME;
  String? hIREDATE;
  int? jOBID;
  String? jOBNAME;
  String? jOBNAMEAr;
  String? jOBNAMEEn;
  int? lEDGERID;
  int? lOCATIONID;
  String? lOCATIONNAME;
  String? mANUALTIMECARDFLAG;
  String? mANUALTIMECARDMEANING;
  String? mobileNumberWithZipCode;
  String? nATIONALITYCODE;
  String? nATIONALITYMEANING;
  String? nATIONALIDENTIFIER;
  String? nORMALHOURS;
  int? nOOFROWS;
  int? oRGANIZATIONID;
  String? oRGANIZATIONNAME;
  String? pAYROLLCODE;
  int? pAYROLLID;
  String? pAYROLLNAME;
  int? pERSONID;
  String? pERSONTYPE;
  int? pERSONTYPEID;
  String? pERINFORMATIONCATEGORY;
  int? pOSITIONID;
  String? pOSITIONNAME;
  String? pRIMARYFLAG;
  int? rOWNUM;
  int? sERVICEDAYS;
  int? sERVICEMONTHS;
  int? sERVICEYEARS;
  String? sUPERVISORASSIGNMENTID;
  String? sUPERVISORDISPLAYNAME;
  String? sUPERVISOREMAILADDRESS;
  int? sUPERVISORID;
  String? sUPERVISORMOBILENUMBER;
  String? sUPERVISORNAME;
  String? sUPERVISORNUMBER;
  String? sUPERVISORWORKNUMBER;
  String? sWIPESEXEMPTEDFLAG;
  String? sWIPESEXEMPTEDMEANING;
  String? sYSTEMPERSONTYPE;
  String? tKEMAILADDRESS;
  String? tKEMPLOYEEDISPLAYNAME;
  String? tKEMPLOYEENAME;
  String? tKEMPLOYEENUMBER;
  int? tKPERSONID;
  int? tOROWNUM;
  String? uNITNUMBER;
  String? uSERSTATUS;

  MemberInformationListModel(
      {this.aCTUALTERMINATIONDATE,
      this.aSSIGNMENTENDDATE,
      this.aSSIGNMENTID,
      this.aSSIGNMENTNUMBER,
      this.aSSIGNMENTSTARTDATE,
      this.aSSIGNMENTSTATUSTYPEID,
      this.aSSIGNMENTTYPE,
      this.bUSINESSGROUPID,
      this.bUSINESSGROUPNAME,
      this.businessCardQR,
      this.cURRENTEMPLOYEEFLAG,
      this.eMPLOYEEDISPLAYNAME,
      this.eMPLOYEEDISPLAYNAMEAr,
      this.eMPLOYEEDISPLAYNAMEEn,
      this.eMPLOYEEEMAILADDRESS,
      this.eMPLOYEEIMAGE,
      this.eMPLOYEEMOBILENUMBER,
      this.eMPLOYEENAME,
      this.eMPLOYEENAMEAr,
      this.eMPLOYEENAMEEn,
      this.eMPLOYEENUMBER,
      this.eMPLOYEEWORKNUMBER,
      this.eMPLOYMENTCATEGORY,
      this.eMPLOYMENTCATEGORYMEANING,
      this.employeeQR,
      this.fREQUENCY,
      this.fREQUENCYMEANING,
      this.fROMROWNUM,
      this.gRADEID,
      this.gRADENAME,
      this.hIREDATE,
      this.jOBID,
      this.jOBNAME,
      this.jOBNAMEAr,
      this.jOBNAMEEn,
      this.lEDGERID,
      this.lOCATIONID,
      this.lOCATIONNAME,
      this.mANUALTIMECARDFLAG,
      this.mANUALTIMECARDMEANING,
      this.mobileNumberWithZipCode,
      this.nATIONALITYCODE,
      this.nATIONALITYMEANING,
      this.nATIONALIDENTIFIER,
      this.nORMALHOURS,
      this.nOOFROWS,
      this.oRGANIZATIONID,
      this.oRGANIZATIONNAME,
      this.pAYROLLCODE,
      this.pAYROLLID,
      this.pAYROLLNAME,
      this.pERSONID,
      this.pERSONTYPE,
      this.pERSONTYPEID,
      this.pERINFORMATIONCATEGORY,
      this.pOSITIONID,
      this.pOSITIONNAME,
      this.pRIMARYFLAG,
      this.rOWNUM,
      this.sERVICEDAYS,
      this.sERVICEMONTHS,
      this.sERVICEYEARS,
      this.sUPERVISORASSIGNMENTID,
      this.sUPERVISORDISPLAYNAME,
      this.sUPERVISOREMAILADDRESS,
      this.sUPERVISORID,
      this.sUPERVISORMOBILENUMBER,
      this.sUPERVISORNAME,
      this.sUPERVISORNUMBER,
      this.sUPERVISORWORKNUMBER,
      this.sWIPESEXEMPTEDFLAG,
      this.sWIPESEXEMPTEDMEANING,
      this.sYSTEMPERSONTYPE,
      this.tKEMAILADDRESS,
      this.tKEMPLOYEEDISPLAYNAME,
      this.tKEMPLOYEENAME,
      this.tKEMPLOYEENUMBER,
      this.tKPERSONID,
      this.tOROWNUM,
      this.uNITNUMBER,
      this.uSERSTATUS});

  MemberInformationListModel.fromJson(Map<String, dynamic> json) {
    aCTUALTERMINATIONDATE = json['ACTUAL_TERMINATION_DATE'];
    aSSIGNMENTENDDATE = json['ASSIGNMENT_END_DATE'];
    aSSIGNMENTID = json['ASSIGNMENT_ID'];
    aSSIGNMENTNUMBER = json['ASSIGNMENT_NUMBER'];
    aSSIGNMENTSTARTDATE = json['ASSIGNMENT_START_DATE'];
    aSSIGNMENTSTATUSTYPEID = json['ASSIGNMENT_STATUS_TYPE_ID'];
    aSSIGNMENTTYPE = json['ASSIGNMENT_TYPE'];
    bUSINESSGROUPID = json['BUSINESS_GROUP_ID'];
    bUSINESSGROUPNAME = json['BUSINESS_GROUP_NAME'];
    businessCardQR = json['BusinessCardQR'];
    cURRENTEMPLOYEEFLAG = json['CURRENT_EMPLOYEE_FLAG'];
    eMPLOYEEDISPLAYNAME = json['EMPLOYEE_DISPLAY_NAME'];
    eMPLOYEEDISPLAYNAMEAr = json['EMPLOYEE_DISPLAY_NAME_Ar'];
    eMPLOYEEDISPLAYNAMEEn = json['EMPLOYEE_DISPLAY_NAME_En'];
    eMPLOYEEEMAILADDRESS = json['EMPLOYEE_EMAIL_ADDRESS'];
    eMPLOYEEIMAGE = json['EMPLOYEE_IMAGE'];
    eMPLOYEEMOBILENUMBER = json['EMPLOYEE_MOBILE_NUMBER'];
    eMPLOYEENAME = json['EMPLOYEE_NAME'];
    eMPLOYEENAMEAr = json['EMPLOYEE_NAME_Ar'];
    eMPLOYEENAMEEn = json['EMPLOYEE_NAME_En'];
    eMPLOYEENUMBER = json['EMPLOYEE_NUMBER'];
    eMPLOYEEWORKNUMBER = json['EMPLOYEE_WORK_NUMBER'];
    eMPLOYMENTCATEGORY = json['EMPLOYMENT_CATEGORY'];
    eMPLOYMENTCATEGORYMEANING = json['EMPLOYMENT_CATEGORY_MEANING'];
    employeeQR = json['EmployeeQR'];
    fREQUENCY = json['FREQUENCY'];
    fREQUENCYMEANING = json['FREQUENCY_MEANING'];
    fROMROWNUM = json['FROM_ROW_NUM'];
    gRADEID = json['GRADE_ID'];
    gRADENAME = json['GRADE_NAME'];
    hIREDATE = json['HIRE_DATE'];
    jOBID = json['JOB_ID'];
    jOBNAME = json['JOB_NAME'];
    jOBNAMEAr = json['JOB_NAME_Ar'];
    jOBNAMEEn = json['JOB_NAME_En'];
    lEDGERID = json['LEDGER_ID'];
    lOCATIONID = json['LOCATION_ID'];
    lOCATIONNAME = json['LOCATION_NAME'];
    mANUALTIMECARDFLAG = json['MANUAL_TIMECARD_FLAG'];
    mANUALTIMECARDMEANING = json['MANUAL_TIMECARD_MEANING'];
    mobileNumberWithZipCode = json['MobileNumberWithZipCode'];
    nATIONALITYCODE = json['NATIONALITY_CODE'];
    nATIONALITYMEANING = json['NATIONALITY_MEANING'];
    nATIONALIDENTIFIER = json['NATIONAL_IDENTIFIER'];
    nORMALHOURS = json['NORMAL_HOURS'];
    nOOFROWS = json['NO_OF_ROWS'];
    oRGANIZATIONID = json['ORGANIZATION_ID'];
    oRGANIZATIONNAME = json['ORGANIZATION_NAME'];
    pAYROLLCODE = json['PAYROLL_CODE'];
    pAYROLLID = json['PAYROLL_ID'];
    pAYROLLNAME = json['PAYROLL_NAME'];
    pERSONID = json['PERSON_ID'];
    pERSONTYPE = json['PERSON_TYPE'];
    pERSONTYPEID = json['PERSON_TYPE_ID'];
    pERINFORMATIONCATEGORY = json['PER_INFORMATION_CATEGORY'];
    pOSITIONID = json['POSITION_ID'];
    pOSITIONNAME = json['POSITION_NAME'];
    pRIMARYFLAG = json['PRIMARY_FLAG'];
    rOWNUM = json['ROW_NUM'];
    sERVICEDAYS = json['SERVICE_DAYS'];
    sERVICEMONTHS = json['SERVICE_MONTHS'];
    sERVICEYEARS = json['SERVICE_YEARS'];
    sUPERVISORASSIGNMENTID = json['SUPERVISOR_ASSIGNMENT_ID'];
    sUPERVISORDISPLAYNAME = json['SUPERVISOR_DISPLAY_NAME'];
    sUPERVISOREMAILADDRESS = json['SUPERVISOR_EMAIL_ADDRESS'];
    sUPERVISORID = json['SUPERVISOR_ID'];
    sUPERVISORMOBILENUMBER = json['SUPERVISOR_MOBILE_NUMBER'];
    sUPERVISORNAME = json['SUPERVISOR_NAME'];
    sUPERVISORNUMBER = json['SUPERVISOR_NUMBER'];
    sUPERVISORWORKNUMBER = json['SUPERVISOR_WORK_NUMBER'];
    sWIPESEXEMPTEDFLAG = json['SWIPES_EXEMPTED_FLAG'];
    sWIPESEXEMPTEDMEANING = json['SWIPES_EXEMPTED_MEANING'];
    sYSTEMPERSONTYPE = json['SYSTEM_PERSON_TYPE'];
    tKEMAILADDRESS = json['TK_EMAIL_ADDRESS'];
    tKEMPLOYEEDISPLAYNAME = json['TK_EMPLOYEE_DISPLAY_NAME'];
    tKEMPLOYEENAME = json['TK_EMPLOYEE_NAME'];
    tKEMPLOYEENUMBER = json['TK_EMPLOYEE_NUMBER'];
    tKPERSONID = json['TK_PERSON_ID'];
    tOROWNUM = json['TO_ROW_NUM'];
    uNITNUMBER = json['UNIT_NUMBER'];
    uSERSTATUS = json['USER_STATUS'];
  }

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = new Map<String, dynamic>();
    data['ACTUAL_TERMINATION_DATE'] = this.aCTUALTERMINATIONDATE;
    data['ASSIGNMENT_END_DATE'] = this.aSSIGNMENTENDDATE;
    data['ASSIGNMENT_ID'] = this.aSSIGNMENTID;
    data['ASSIGNMENT_NUMBER'] = this.aSSIGNMENTNUMBER;
    data['ASSIGNMENT_START_DATE'] = this.aSSIGNMENTSTARTDATE;
    data['ASSIGNMENT_STATUS_TYPE_ID'] = this.aSSIGNMENTSTATUSTYPEID;
    data['ASSIGNMENT_TYPE'] = this.aSSIGNMENTTYPE;
    data['BUSINESS_GROUP_ID'] = this.bUSINESSGROUPID;
    data['BUSINESS_GROUP_NAME'] = this.bUSINESSGROUPNAME;
    data['BusinessCardQR'] = this.businessCardQR;
    data['CURRENT_EMPLOYEE_FLAG'] = this.cURRENTEMPLOYEEFLAG;
    data['EMPLOYEE_DISPLAY_NAME'] = this.eMPLOYEEDISPLAYNAME;
    data['EMPLOYEE_DISPLAY_NAME_Ar'] = this.eMPLOYEEDISPLAYNAMEAr;
    data['EMPLOYEE_DISPLAY_NAME_En'] = this.eMPLOYEEDISPLAYNAMEEn;
    data['EMPLOYEE_EMAIL_ADDRESS'] = this.eMPLOYEEEMAILADDRESS;
    data['EMPLOYEE_IMAGE'] = this.eMPLOYEEIMAGE;
    data['EMPLOYEE_MOBILE_NUMBER'] = this.eMPLOYEEMOBILENUMBER;
    data['EMPLOYEE_NAME'] = this.eMPLOYEENAME;
    data['EMPLOYEE_NAME_Ar'] = this.eMPLOYEENAMEAr;
    data['EMPLOYEE_NAME_En'] = this.eMPLOYEENAMEEn;
    data['EMPLOYEE_NUMBER'] = this.eMPLOYEENUMBER;
    data['EMPLOYEE_WORK_NUMBER'] = this.eMPLOYEEWORKNUMBER;
    data['EMPLOYMENT_CATEGORY'] = this.eMPLOYMENTCATEGORY;
    data['EMPLOYMENT_CATEGORY_MEANING'] = this.eMPLOYMENTCATEGORYMEANING;
    data['EmployeeQR'] = this.employeeQR;
    data['FREQUENCY'] = this.fREQUENCY;
    data['FREQUENCY_MEANING'] = this.fREQUENCYMEANING;
    data['FROM_ROW_NUM'] = this.fROMROWNUM;
    data['GRADE_ID'] = this.gRADEID;
    data['GRADE_NAME'] = this.gRADENAME;
    data['HIRE_DATE'] = this.hIREDATE;
    data['JOB_ID'] = this.jOBID;
    data['JOB_NAME'] = this.jOBNAME;
    data['JOB_NAME_Ar'] = this.jOBNAMEAr;
    data['JOB_NAME_En'] = this.jOBNAMEEn;
    data['LEDGER_ID'] = this.lEDGERID;
    data['LOCATION_ID'] = this.lOCATIONID;
    data['LOCATION_NAME'] = this.lOCATIONNAME;
    data['MANUAL_TIMECARD_FLAG'] = this.mANUALTIMECARDFLAG;
    data['MANUAL_TIMECARD_MEANING'] = this.mANUALTIMECARDMEANING;
    data['MobileNumberWithZipCode'] = this.mobileNumberWithZipCode;
    data['NATIONALITY_CODE'] = this.nATIONALITYCODE;
    data['NATIONALITY_MEANING'] = this.nATIONALITYMEANING;
    data['NATIONAL_IDENTIFIER'] = this.nATIONALIDENTIFIER;
    data['NORMAL_HOURS'] = this.nORMALHOURS;
    data['NO_OF_ROWS'] = this.nOOFROWS;
    data['ORGANIZATION_ID'] = this.oRGANIZATIONID;
    data['ORGANIZATION_NAME'] = this.oRGANIZATIONNAME;
    data['PAYROLL_CODE'] = this.pAYROLLCODE;
    data['PAYROLL_ID'] = this.pAYROLLID;
    data['PAYROLL_NAME'] = this.pAYROLLNAME;
    data['PERSON_ID'] = this.pERSONID;
    data['PERSON_TYPE'] = this.pERSONTYPE;
    data['PERSON_TYPE_ID'] = this.pERSONTYPEID;
    data['PER_INFORMATION_CATEGORY'] = this.pERINFORMATIONCATEGORY;
    data['POSITION_ID'] = this.pOSITIONID;
    data['POSITION_NAME'] = this.pOSITIONNAME;
    data['PRIMARY_FLAG'] = this.pRIMARYFLAG;
    data['ROW_NUM'] = this.rOWNUM;
    data['SERVICE_DAYS'] = this.sERVICEDAYS;
    data['SERVICE_MONTHS'] = this.sERVICEMONTHS;
    data['SERVICE_YEARS'] = this.sERVICEYEARS;
    data['SUPERVISOR_ASSIGNMENT_ID'] = this.sUPERVISORASSIGNMENTID;
    data['SUPERVISOR_DISPLAY_NAME'] = this.sUPERVISORDISPLAYNAME;
    data['SUPERVISOR_EMAIL_ADDRESS'] = this.sUPERVISOREMAILADDRESS;
    data['SUPERVISOR_ID'] = this.sUPERVISORID;
    data['SUPERVISOR_MOBILE_NUMBER'] = this.sUPERVISORMOBILENUMBER;
    data['SUPERVISOR_NAME'] = this.sUPERVISORNAME;
    data['SUPERVISOR_NUMBER'] = this.sUPERVISORNUMBER;
    data['SUPERVISOR_WORK_NUMBER'] = this.sUPERVISORWORKNUMBER;
    data['SWIPES_EXEMPTED_FLAG'] = this.sWIPESEXEMPTEDFLAG;
    data['SWIPES_EXEMPTED_MEANING'] = this.sWIPESEXEMPTEDMEANING;
    data['SYSTEM_PERSON_TYPE'] = this.sYSTEMPERSONTYPE;
    data['TK_EMAIL_ADDRESS'] = this.tKEMAILADDRESS;
    data['TK_EMPLOYEE_DISPLAY_NAME'] = this.tKEMPLOYEEDISPLAYNAME;
    data['TK_EMPLOYEE_NAME'] = this.tKEMPLOYEENAME;
    data['TK_EMPLOYEE_NUMBER'] = this.tKEMPLOYEENUMBER;
    data['TK_PERSON_ID'] = this.tKPERSONID;
    data['TO_ROW_NUM'] = this.tOROWNUM;
    data['UNIT_NUMBER'] = this.uNITNUMBER;
    data['USER_STATUS'] = this.uSERSTATUS;
    return data;
  }

  String getPositionName() {
    String positionName = "";
    List<String> list = pOSITIONNAME?.split(".") ?? [];
    if (list.isNotEmpty) {
      if (list.length > 1) {
        positionName = list[0] + " " + list[1];
      } else {
        positionName = list.first;
      }
    }
    return positionName;
  }

  static Future<List<MemberInformationListModel>> getFromPrefs() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    List encodedList = prefs.getStringList(SharedPrefsConsts.memberInformation) ?? [];
    return encodedList.map((e) => MemberInformationListModel.fromJson(jsonDecode(e))).toList();
  }

  static void saveToPrefs(List<MemberInformationListModel> list) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    List<String> encodedList = list.map((e) => jsonEncode(e.toJson())).toList();
    await prefs.setStringList(SharedPrefsConsts.memberInformation, encodedList);
  }
}
