// ignore_for_file: non_constant_identifier_names
// ignore_for_file: camel_case_types
// ignore_for_file: prefer_single_quotes

// This file is automatically generated. DO NOT EDIT, all your changes would be lost.
import 'package:flutter/material.dart' show debugPrint;
import 'package:domain/entity/response/attendance_entity.dart';
import 'package:domain/entity/response/check_success_entity.dart';
import 'package:domain/entity/response/hotel_info_entity.dart';
import 'package:domain/entity/response/id_name_entity.dart';
import 'package:domain/entity/response/job_list_add_staff_entity.dart';
import 'package:domain/entity/response/job_list_applied_edit_entity.dart';
import 'package:domain/entity/response/job_list_applied_info_entity.dart';
import 'package:domain/entity/response/job_list_applied_staff_list_entity.dart';
import 'package:domain/entity/response/job_list_applied_staff_search_entity.dart';
import 'package:domain/entity/response/job_list_applied_work_flow_entity.dart';
import 'package:domain/entity/response/job_list_detail_entity.dart';
import 'package:domain/entity/response/job_list_entity.dart';
import 'package:domain/entity/response/job_list_index_entity.dart';
import 'package:domain/entity/response/job_list_remark_view_entity.dart';
import 'package:domain/entity/response/labour_request_edit_index_entity.dart';
import 'package:domain/entity/response/labour_request_index_entity.dart';
import 'package:domain/entity/response/labour_request_list_entity.dart';
import 'package:domain/entity/response/labour_request_work_flow_entity.dart';
import 'package:domain/entity/response/staff_detail_entity.dart';
import 'package:domain/entity/response/staff_labour_history_entity.dart';
import 'package:domain/entity/response/staff_remark_history_entity.dart';
import 'package:domain/entity/server_time.dart';

JsonConvert jsonConvert = JsonConvert();

typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json);
typedef EnumConvertFunction<T> = T Function(String value);
typedef ConvertExceptionHandler = void Function(Object error, StackTrace stackTrace);
extension MapSafeExt<K, V> on Map<K, V> {
  T? getOrNull<T>(K? key) {
    if (!containsKey(key) || key == null) {
      return null;
    } else {
      return this[key] as T?;
    }
  }
}

class JsonConvert {
  static ConvertExceptionHandler? onError;
  JsonConvertClassCollection convertFuncMap = JsonConvertClassCollection();

  /// When you are in the development, to generate a new model class, hot-reload doesn't find new generation model class, you can build on MaterialApp method called jsonConvert. ReassembleConvertFuncMap (); This method only works in a development environment
  /// https://flutter.cn/docs/development/tools/hot-reload
  /// class MyApp extends StatelessWidget {
  ///    const MyApp({Key? key})
  ///        : super(key: key);
  ///
  ///    @override
  ///    Widget build(BuildContext context) {
  ///      jsonConvert.reassembleConvertFuncMap();
  ///      return MaterialApp();
  ///    }
  /// }
  void reassembleConvertFuncMap() {
    bool isReleaseMode = const bool.fromEnvironment('dart.vm.product');
    if (!isReleaseMode) {
      convertFuncMap = JsonConvertClassCollection();
    }
  }

  T? convert<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
    if (value == null) {
      return null;
    }
    if (value is T) {
      return value;
    }
    try {
      return _asT<T>(value, enumConvert: enumConvert);
    } catch (e, stackTrace) {
      debugPrint('asT<$T> $e $stackTrace');
      if (onError != null) {
        onError!(e, stackTrace);
      }
      return null;
    }
  }

  List<T?>? convertList<T>(List<dynamic>? value, {EnumConvertFunction? enumConvert}) {
    if (value == null) {
      return null;
    }
    try {
      return value.map((dynamic e) => _asT<T>(e, enumConvert: enumConvert)).toList();
    } catch (e, stackTrace) {
      debugPrint('asT<$T> $e $stackTrace');
      if (onError != null) {
        onError!(e, stackTrace);
      }
      return <T>[];
    }
  }

  List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
    if (value == null) {
      return null;
    }
    try {
      return (value as List<dynamic>).map((dynamic e) => _asT<T>(e, enumConvert: enumConvert)!).toList();
    } catch (e, stackTrace) {
      debugPrint('asT<$T> $e $stackTrace');
      if (onError != null) {
        onError!(e, stackTrace);
      }
      return <T>[];
    }
  }

  T? _asT<T extends Object?>(dynamic value,
      {EnumConvertFunction? enumConvert}) {
    final String type = T.toString();
    final String valueS = value.toString();
    if (enumConvert != null) {
      return enumConvert(valueS) as T;
    } else if (type == "String") {
      return valueS as T;
    } else if (type == "int") {
      final int? intValue = int.tryParse(valueS);
      if (intValue == null) {
        return double.tryParse(valueS)?.toInt() as T?;
      } else {
        return intValue as T;
      }
    } else if (type == "double") {
      return double.parse(valueS) as T;
    } else if (type == "DateTime") {
      return DateTime.parse(valueS) as T;
    } else if (type == "bool") {
      if (valueS == '0' || valueS == '1') {
        return (valueS == '1') as T;
      }
      return (valueS == 'true') as T;
    } else if (type == "Map" || type.startsWith("Map<")) {
      return value as T;
    } else {
      if (convertFuncMap.containsKey(type)) {
        if (value == null) {
          return null;
        }
        return convertFuncMap[type]!(value as Map<String, dynamic>) as T;
      } else {
        throw UnimplementedError('$type unimplemented,you can try running the app again');
      }
    }
  }

  //list is returned by type
  static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
    if (<AttendanceEntity>[] is M) {
      return data.map<AttendanceEntity>((Map<String, dynamic> e) => AttendanceEntity.fromJson(e)).toList() as M;
    }
    if (<AttendanceList>[] is M) {
      return data.map<AttendanceList>((Map<String, dynamic> e) => AttendanceList.fromJson(e)).toList() as M;
    }
    if (<CheckSuccessEntity>[] is M) {
      return data.map<CheckSuccessEntity>((Map<String, dynamic> e) => CheckSuccessEntity.fromJson(e)).toList() as M;
    }
    if (<HotelInfoEntity>[] is M) {
      return data.map<HotelInfoEntity>((Map<String, dynamic> e) => HotelInfoEntity.fromJson(e)).toList() as M;
    }
    if (<HotelInfoMenus>[] is M) {
      return data.map<HotelInfoMenus>((Map<String, dynamic> e) => HotelInfoMenus.fromJson(e)).toList() as M;
    }
    if (<HotelInfoMenusChildren>[] is M) {
      return data.map<HotelInfoMenusChildren>((Map<String, dynamic> e) => HotelInfoMenusChildren.fromJson(e)).toList() as M;
    }
    if (<IdNameEntity>[] is M) {
      return data.map<IdNameEntity>((Map<String, dynamic> e) => IdNameEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAddStaffEntity>[] is M) {
      return data.map<JobListAddStaffEntity>((Map<String, dynamic> e) => JobListAddStaffEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAddStaffResultList>[] is M) {
      return data.map<JobListAddStaffResultList>((Map<String, dynamic> e) => JobListAddStaffResultList.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedEditEntity>[] is M) {
      return data.map<JobListAppliedEditEntity>((Map<String, dynamic> e) => JobListAppliedEditEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedEditReasonList>[] is M) {
      return data.map<JobListAppliedEditReasonList>((Map<String, dynamic> e) => JobListAppliedEditReasonList.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedInfoEntity>[] is M) {
      return data.map<JobListAppliedInfoEntity>((Map<String, dynamic> e) => JobListAppliedInfoEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffListEntity>[] is M) {
      return data.map<JobListAppliedStaffListEntity>((Map<String, dynamic> e) => JobListAppliedStaffListEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffListRows>[] is M) {
      return data.map<JobListAppliedStaffListRows>((Map<String, dynamic> e) => JobListAppliedStaffListRows.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffListRowsSecurityIn>[] is M) {
      return data.map<JobListAppliedStaffListRowsSecurityIn>((Map<String, dynamic> e) => JobListAppliedStaffListRowsSecurityIn.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffListRowsSecurityOut>[] is M) {
      return data.map<JobListAppliedStaffListRowsSecurityOut>((Map<String, dynamic> e) => JobListAppliedStaffListRowsSecurityOut.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffListRowsWorkIn>[] is M) {
      return data.map<JobListAppliedStaffListRowsWorkIn>((Map<String, dynamic> e) => JobListAppliedStaffListRowsWorkIn.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffListRowsWorkOut>[] is M) {
      return data.map<JobListAppliedStaffListRowsWorkOut>((Map<String, dynamic> e) => JobListAppliedStaffListRowsWorkOut.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffSearchEntity>[] is M) {
      return data.map<JobListAppliedStaffSearchEntity>((Map<String, dynamic> e) => JobListAppliedStaffSearchEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedStaffSearchRows>[] is M) {
      return data.map<JobListAppliedStaffSearchRows>((Map<String, dynamic> e) => JobListAppliedStaffSearchRows.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedWorkFlowEntity>[] is M) {
      return data.map<JobListAppliedWorkFlowEntity>((Map<String, dynamic> e) => JobListAppliedWorkFlowEntity.fromJson(e)).toList() as M;
    }
    if (<JobListAppliedWorkFlowRecords>[] is M) {
      return data.map<JobListAppliedWorkFlowRecords>((Map<String, dynamic> e) => JobListAppliedWorkFlowRecords.fromJson(e)).toList() as M;
    }
    if (<JobListDetailEntity>[] is M) {
      return data.map<JobListDetailEntity>((Map<String, dynamic> e) => JobListDetailEntity.fromJson(e)).toList() as M;
    }
    if (<JobListDetailDepartmentList>[] is M) {
      return data.map<JobListDetailDepartmentList>((Map<String, dynamic> e) => JobListDetailDepartmentList.fromJson(e)).toList() as M;
    }
    if (<JobListEntity>[] is M) {
      return data.map<JobListEntity>((Map<String, dynamic> e) => JobListEntity.fromJson(e)).toList() as M;
    }
    if (<JobListRows>[] is M) {
      return data.map<JobListRows>((Map<String, dynamic> e) => JobListRows.fromJson(e)).toList() as M;
    }
    if (<JobListIndexEntity>[] is M) {
      return data.map<JobListIndexEntity>((Map<String, dynamic> e) => JobListIndexEntity.fromJson(e)).toList() as M;
    }
    if (<JobListIndexDepartmentList>[] is M) {
      return data.map<JobListIndexDepartmentList>((Map<String, dynamic> e) => JobListIndexDepartmentList.fromJson(e)).toList() as M;
    }
    if (<JobListIndexStatusList>[] is M) {
      return data.map<JobListIndexStatusList>((Map<String, dynamic> e) => JobListIndexStatusList.fromJson(e)).toList() as M;
    }
    if (<JobListRemarkViewEntity>[] is M) {
      return data.map<JobListRemarkViewEntity>((Map<String, dynamic> e) => JobListRemarkViewEntity.fromJson(e)).toList() as M;
    }
    if (<LabourRequestEditIndexEntity>[] is M) {
      return data.map<LabourRequestEditIndexEntity>((Map<String, dynamic> e) => LabourRequestEditIndexEntity.fromJson(e)).toList() as M;
    }
    if (<LabourRequestEditIndexTemplateList>[] is M) {
      return data.map<LabourRequestEditIndexTemplateList>((Map<String, dynamic> e) => LabourRequestEditIndexTemplateList.fromJson(e)).toList() as M;
    }
    if (<LabourRequestEditIndexDepartmentList>[] is M) {
      return data.map<LabourRequestEditIndexDepartmentList>((Map<String, dynamic> e) => LabourRequestEditIndexDepartmentList.fromJson(e)).toList() as M;
    }
    if (<LabourRequestIndexEntity>[] is M) {
      return data.map<LabourRequestIndexEntity>((Map<String, dynamic> e) => LabourRequestIndexEntity.fromJson(e)).toList() as M;
    }
    if (<LabourRequestIndexDepartmentList>[] is M) {
      return data.map<LabourRequestIndexDepartmentList>((Map<String, dynamic> e) => LabourRequestIndexDepartmentList.fromJson(e)).toList() as M;
    }
    if (<LabourRequestIndexStatusList>[] is M) {
      return data.map<LabourRequestIndexStatusList>((Map<String, dynamic> e) => LabourRequestIndexStatusList.fromJson(e)).toList() as M;
    }
    if (<LabourRequestListEntity>[] is M) {
      return data.map<LabourRequestListEntity>((Map<String, dynamic> e) => LabourRequestListEntity.fromJson(e)).toList() as M;
    }
    if (<LabourRequestListRows>[] is M) {
      return data.map<LabourRequestListRows>((Map<String, dynamic> e) => LabourRequestListRows.fromJson(e)).toList() as M;
    }
    if (<LabourRequestWorkFlowEntity>[] is M) {
      return data.map<LabourRequestWorkFlowEntity>((Map<String, dynamic> e) => LabourRequestWorkFlowEntity.fromJson(e)).toList() as M;
    }
    if (<LabourRequestWorkFlowRecords>[] is M) {
      return data.map<LabourRequestWorkFlowRecords>((Map<String, dynamic> e) => LabourRequestWorkFlowRecords.fromJson(e)).toList() as M;
    }
    if (<StaffDetailEntity>[] is M) {
      return data.map<StaffDetailEntity>((Map<String, dynamic> e) => StaffDetailEntity.fromJson(e)).toList() as M;
    }
    if (<StaffLabourHistoryEntity>[] is M) {
      return data.map<StaffLabourHistoryEntity>((Map<String, dynamic> e) => StaffLabourHistoryEntity.fromJson(e)).toList() as M;
    }
    if (<StaffLabourHistoryRows>[] is M) {
      return data.map<StaffLabourHistoryRows>((Map<String, dynamic> e) => StaffLabourHistoryRows.fromJson(e)).toList() as M;
    }
    if (<StaffLabourHistoryRowsSecurityIn>[] is M) {
      return data.map<StaffLabourHistoryRowsSecurityIn>((Map<String, dynamic> e) => StaffLabourHistoryRowsSecurityIn.fromJson(e)).toList() as M;
    }
    if (<StaffLabourHistoryRowsSecurityOut>[] is M) {
      return data.map<StaffLabourHistoryRowsSecurityOut>((Map<String, dynamic> e) => StaffLabourHistoryRowsSecurityOut.fromJson(e)).toList() as M;
    }
    if (<StaffLabourHistoryRowsWorkIn>[] is M) {
      return data.map<StaffLabourHistoryRowsWorkIn>((Map<String, dynamic> e) => StaffLabourHistoryRowsWorkIn.fromJson(e)).toList() as M;
    }
    if (<StaffLabourHistoryRowsWorkOut>[] is M) {
      return data.map<StaffLabourHistoryRowsWorkOut>((Map<String, dynamic> e) => StaffLabourHistoryRowsWorkOut.fromJson(e)).toList() as M;
    }
    if (<StaffRemarkHistoryEntity>[] is M) {
      return data.map<StaffRemarkHistoryEntity>((Map<String, dynamic> e) => StaffRemarkHistoryEntity.fromJson(e)).toList() as M;
    }
    if (<StaffRemarkHistoryRows>[] is M) {
      return data.map<StaffRemarkHistoryRows>((Map<String, dynamic> e) => StaffRemarkHistoryRows.fromJson(e)).toList() as M;
    }
    if (<ServerTime>[] is M) {
      return data.map<ServerTime>((Map<String, dynamic> e) => ServerTime.fromJson(e)).toList() as M;
    }

    debugPrint("$M not found");

    return null;
  }

  static M? fromJsonAsT<M>(dynamic json) {
    if (json is M) {
      return json;
    }
    if (json is List) {
      return _getListChildType<M>(json.map((dynamic e) => e as Map<String, dynamic>).toList());
    } else {
      return jsonConvert.convert<M>(json);
    }
  }
}

class JsonConvertClassCollection {
  Map<String, JsonConvertFunction> convertFuncMap = {
    (AttendanceEntity).toString(): AttendanceEntity.fromJson,
    (AttendanceList).toString(): AttendanceList.fromJson,
    (CheckSuccessEntity).toString(): CheckSuccessEntity.fromJson,
    (HotelInfoEntity).toString(): HotelInfoEntity.fromJson,
    (HotelInfoMenus).toString(): HotelInfoMenus.fromJson,
    (HotelInfoMenusChildren).toString(): HotelInfoMenusChildren.fromJson,
    (IdNameEntity).toString(): IdNameEntity.fromJson,
    (JobListAddStaffEntity).toString(): JobListAddStaffEntity.fromJson,
    (JobListAddStaffResultList).toString(): JobListAddStaffResultList.fromJson,
    (JobListAppliedEditEntity).toString(): JobListAppliedEditEntity.fromJson,
    (JobListAppliedEditReasonList).toString(): JobListAppliedEditReasonList.fromJson,
    (JobListAppliedInfoEntity).toString(): JobListAppliedInfoEntity.fromJson,
    (JobListAppliedStaffListEntity).toString(): JobListAppliedStaffListEntity.fromJson,
    (JobListAppliedStaffListRows).toString(): JobListAppliedStaffListRows.fromJson,
    (JobListAppliedStaffListRowsSecurityIn).toString(): JobListAppliedStaffListRowsSecurityIn.fromJson,
    (JobListAppliedStaffListRowsSecurityOut).toString(): JobListAppliedStaffListRowsSecurityOut.fromJson,
    (JobListAppliedStaffListRowsWorkIn).toString(): JobListAppliedStaffListRowsWorkIn.fromJson,
    (JobListAppliedStaffListRowsWorkOut).toString(): JobListAppliedStaffListRowsWorkOut.fromJson,
    (JobListAppliedStaffSearchEntity).toString(): JobListAppliedStaffSearchEntity.fromJson,
    (JobListAppliedStaffSearchRows).toString(): JobListAppliedStaffSearchRows.fromJson,
    (JobListAppliedWorkFlowEntity).toString(): JobListAppliedWorkFlowEntity.fromJson,
    (JobListAppliedWorkFlowRecords).toString(): JobListAppliedWorkFlowRecords.fromJson,
    (JobListDetailEntity).toString(): JobListDetailEntity.fromJson,
    (JobListDetailDepartmentList).toString(): JobListDetailDepartmentList.fromJson,
    (JobListEntity).toString(): JobListEntity.fromJson,
    (JobListRows).toString(): JobListRows.fromJson,
    (JobListIndexEntity).toString(): JobListIndexEntity.fromJson,
    (JobListIndexDepartmentList).toString(): JobListIndexDepartmentList.fromJson,
    (JobListIndexStatusList).toString(): JobListIndexStatusList.fromJson,
    (JobListRemarkViewEntity).toString(): JobListRemarkViewEntity.fromJson,
    (LabourRequestEditIndexEntity).toString(): LabourRequestEditIndexEntity.fromJson,
    (LabourRequestEditIndexTemplateList).toString(): LabourRequestEditIndexTemplateList.fromJson,
    (LabourRequestEditIndexDepartmentList).toString(): LabourRequestEditIndexDepartmentList.fromJson,
    (LabourRequestIndexEntity).toString(): LabourRequestIndexEntity.fromJson,
    (LabourRequestIndexDepartmentList).toString(): LabourRequestIndexDepartmentList.fromJson,
    (LabourRequestIndexStatusList).toString(): LabourRequestIndexStatusList.fromJson,
    (LabourRequestListEntity).toString(): LabourRequestListEntity.fromJson,
    (LabourRequestListRows).toString(): LabourRequestListRows.fromJson,
    (LabourRequestWorkFlowEntity).toString(): LabourRequestWorkFlowEntity.fromJson,
    (LabourRequestWorkFlowRecords).toString(): LabourRequestWorkFlowRecords.fromJson,
    (StaffDetailEntity).toString(): StaffDetailEntity.fromJson,
    (StaffLabourHistoryEntity).toString(): StaffLabourHistoryEntity.fromJson,
    (StaffLabourHistoryRows).toString(): StaffLabourHistoryRows.fromJson,
    (StaffLabourHistoryRowsSecurityIn).toString(): StaffLabourHistoryRowsSecurityIn.fromJson,
    (StaffLabourHistoryRowsSecurityOut).toString(): StaffLabourHistoryRowsSecurityOut.fromJson,
    (StaffLabourHistoryRowsWorkIn).toString(): StaffLabourHistoryRowsWorkIn.fromJson,
    (StaffLabourHistoryRowsWorkOut).toString(): StaffLabourHistoryRowsWorkOut.fromJson,
    (StaffRemarkHistoryEntity).toString(): StaffRemarkHistoryEntity.fromJson,
    (StaffRemarkHistoryRows).toString(): StaffRemarkHistoryRows.fromJson,
    (ServerTime).toString(): ServerTime.fromJson,
  };

  bool containsKey(String type) {
    return convertFuncMap.containsKey(type);
  }

  JsonConvertFunction? operator [](String key) {
    return convertFuncMap[key];
  }
}