import 'package:test_sa/models/device/asset.dart';
import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/new_models/assistant_employee.dart';
import 'package:test_sa/models/new_models/work_order_detail_model.dart';
import 'package:test_sa/models/ppm/ppm.dart';
import 'package:test_sa/models/timer_model.dart';

import 'asset_transfer_attachment.dart';

class DeviceTransfer {
  DeviceTransfer({
    this.id,
    this.transferNo,
    this.transferType,
    this.transferCode,
    this.assetId,
    this.destSiteId,
    this.destBuildingId,
    this.destFloorId,
    this.destDepartmentId,
    this.destRoomId,
    this.senderSiteId,
    this.senderBuildingId,
    this.senderFloorId,
    this.senderDepartmentId,
    this.senderRoom,
    this.senderAssignedEmployeeId,
    this.senderMachineStatusId,
    this.senderComment,
    this.nurseSignature,
    this.comment,
    this.receiverEndUserId,
    this.receiverEndUserName,
    this.senderStartDate,
    this.senderEndDate,
    this.senderWorkingHours,
    this.senderTravelingHours,
    this.senderEngSignature,
    this.senderAttachments,
    this.receiverAssignedEmployeeId,
    this.receiverAssignedEmployeeNumber,
    this.receiverMachineStatusId,
    this.senderMachineStatusValue,
    this.receiverComment,
    this.receiverStartDate,
    this.receiverEndDate,
    this.receiverWorkingHours,
    this.receiverTravelingHours,
    this.receiverEngSignature,
    this.receiverAttachments,
    this.assetTransferAttachments,
    this.assetTransferContactPersons,
    this.attachments,
    this.assetNumber,
    this.assetName,
    this.manufacturerName,
    this.modelName,
    this.assetSerialNo,
    this.destDepartmentName,
    this.destBuildingName,
    this.applied,
    this.isSender,
    this.extensionNo,
    this.name,
    this.employeeId,
    this.createdDate,
    this.createdOn,
    this.destFloorName,
    this.destSiteName,
    this.manufacturerId,
    this.modelId,
    this.modifiedOn,
    this.receiverAssignedEmployeeName,
    this.receiverEngSignatureUrl,
    this.receiverMachineStatusValue,
    this.receiverMachineStatusName,
    this.senderAssignedEmployeeName,
    this.senderAssignedEmployeeNumber,
    this.senderBuildingName,
    this.senderDepartmentName,
    this.senderEngSignatureUrl,
    this.senderFloorName,
    this.senderMachineStatusName,
    this.senderSiteName,
    this.supplierId,
    this.supplierName,
    this.senderVisitTimers,
    this.receiverVisitTimers,
    this.assetTransferEngineerTimers,
    this.tbsTimer,
    this.deviceTimePicker,
    this.timerModelList,
    this.assistantEmployees,
    this.modelAssistantEmployees,
    this.assistantEmployList,
    this.assetTransferAssistantEmployeesReceiver,
    this.assetTransferAssistantEmployeesSender,
    this.statusValue,
  });

  DeviceTransfer.fromJson(dynamic json) {
    id = json['id'];
    transferNo = json['transferNo'];
    transferCode = json['transferCode'];
    transferType = json["transferType"] == null ? null : Lookup.fromJson(json["transferType"]);
    assetId = json['assetId'];
    destSiteId = json['destSiteId'];
    destBuildingId = json['destBuildingId'];
    destFloorId = json['destFloorId'];
    destDepartmentId = json['destDepartmentId'];
    destRoomId = json['destRoomId'];
    senderSiteId = json['senderSiteId'];
    senderBuildingId = json['senderBuildingId'];
    senderFloorId = json['senderFloorId'];
    senderDepartmentId = json['senderDepartmentId'];
    senderRoom = json['senderRoom'];
    senderAssignedEmployeeId = json['senderAssignedEmployeeId'];
    senderMachineStatusId = json['senderMachineStatusId'];
    senderMachineStatusValue = json['senderMachineStatusValue'];
    senderComment = json['senderComment'];
    comment = json['comment'];
    receiverEndUserId = json['receiverEndUserId'];
    receiverEndUserName = json['receiverEndUserName'];
    senderStartDate = json['senderStartDate'];
    senderEndDate = json['senderEndDate'];
    senderWorkingHours = json['senderWorkingHours'];
    senderTravelingHours = json['senderTravelingHours'];
    senderEngSignature = json['senderEngSignature'];
    if (json['senderAttachments'] != null) {
      senderAttachments = [];
      json['senderAttachments'].forEach((v) {
        senderAttachments!.add(GenericAttachmentModel.fromAssetTransferJson(v));
      });
    }
    if (json['assetTransferAttachments'] != null) {
      assetTransferAttachments = [];
      json['assetTransferAttachments'].forEach((v) {
        assetTransferAttachments?.add(GenericAttachmentModel.fromAssetTransferJson(v));
      });
    }
    if (json['assetTransferContactPersons'] != null) {
      assetTransferContactPersons = [];
      json['assetTransferContactPersons'].forEach((v) {
        assetTransferContactPersons?.add(AssetTransferContactPerson.fromJson(v));
      });
    }
    receiverAssignedEmployeeId = json['receiverAssignedEmployeeId'];
    receiverAssignedEmployeeNumber = json['receiverAssignedEmployeeNumber'];
    receiverMachineStatusId = json['receiverMachineStatusId'];
    receiverMachineStatusValue = json['receiverMachineStatusValue'];
    receiverComment = json['receiverComment'];
    receiverStartDate = json['receiverStartDate'];
    receiverEndDate = json['receiverEndDate'];
    receiverWorkingHours = json['receiverWorkingHours'];
    receiverTravelingHours = json['receiverTravelingHours'];
    receiverEngSignature = json['receiverEngSignature'];
    senderVisitTimers = <VisitTimers>[];
    if (json['assetTransferSenderTimers'] != null) {
      json['assetTransferSenderTimers'].forEach((v) {
        senderVisitTimers!.add(VisitTimers.fromJson(v));
      });
    }
    receiverVisitTimers = <VisitTimers>[];
    if (json['assetTransferReceiverTimers'] != null) {
      json['assetTransferReceiverTimers'].forEach((v) {
        receiverVisitTimers!.add(VisitTimers.fromJson(v));
      });
    }
    if (json['assetTransferAssistantEmployeesSender'] != null) {
      assetTransferAssistantEmployeesSender = [];
      json['assetTransferAssistantEmployeesSender'].forEach((v) {
        assetTransferAssistantEmployeesSender!.add(AssetTransferAssistantEmployees.fromJson(v));
      });
    }
    if (json['assetTransferAssistantEmployeesReceiver'] != null) {
      assetTransferAssistantEmployeesReceiver = [];
      json['assetTransferAssistantEmployeesReceiver'].forEach((v) {
        assetTransferAssistantEmployeesReceiver!.add(AssetTransferAssistantEmployees.fromJson(v));
      });
    }

    tbsTimer = TimerModel();
    // try {
    //   receiverTimer = TimerModel(startAt: DateTime.tryParse(receiverStartDate ?? ""), endAt: DateTime.tryParse(receiverEndDate ?? ""));
    //   senderTimer = TimerModel(startAt: DateTime.tryParse(senderStartDate ?? ""), endAt: DateTime.tryParse(senderEndDate ?? ""));
    //   if (receiverTimer.endAt != null && receiverTimer.startAt != null) {
    //     receiverTimer.durationInSecond = (receiverTimer.endAt.difference(receiverTimer.startAt))?.inSeconds;
    //     receiverWorkingHours = (((receiverTimer.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2);
    //   }
    //   if (senderTimer.endAt != null && senderTimer.startAt != null) {
    //     senderTimer.durationInSecond = (senderTimer.endAt.difference(senderTimer.startAt))?.inSeconds;
    //     senderWorkingHours = (((senderTimer.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2);
    //   }
    // } catch (e) {
    //   print(e);
    // }
    if (json['receiverAttachments'] != null) {
      receiverAttachments = [];
      json['receiverAttachments'].forEach((v) {
        receiverAttachments!.add(GenericAttachmentModel.fromAssetTransferJson(v));
      });
    }
    assetNumber = json['assetNumber'];
    assetName = json['assetName'];
    manufacturerName = json['manufacturerName'];
    modelName = json['modelName'];
    assetSerialNo = json['assetSerialNo'];
    destDepartmentName = json['destDepartmentName'];
    destBuildingName = json['destBuildingName'];
    applied = json['applied'];
    extensionNo = json['extensionNo'];
    employeeId = json['employeeId'];
    name = json['name'];
    createdDate = json['createdDate'];
    createdOn = json['createdOn'];
    destFloorName = json['destFloorName'];
    destSiteName = json['destSiteName'];
    manufacturerId = json['manufacturerId'];
    modelId = json['modelId'];
    modifiedOn = json['modifiedOn'];
    receiverAssignedEmployeeName = json['receiverAssignedEmployeeName'];
    receiverEngSignatureUrl = json['receiverEngSignatureUrl'];
    receiverMachineStatusName = json['receiverMachineStatusName'];
    senderAssignedEmployeeName = json['senderAssignedEmployeeName'];
    senderAssignedEmployeeNumber = json['senderAssignedEmployeeNumber'];
    senderBuildingName = json['senderBuildingName'];
    senderDepartmentName = json['senderDepartmentName'];
    senderEngSignatureUrl = json['senderEngSignatureUrl'];
    senderFloorName = json['senderFloorName'];
    senderMachineStatusName = json['senderMachineStatusName'];
    senderSiteName = json['senderSiteName'];
    supplierId = json['supplierId'];
    supplierName = json['supplierName'];
  }

  num? id;
  num? transferNo;
  String? transferCode;
  int? statusValue;
  String? nurseSignature;
  Lookup? transferType;
  String? assetSerialNo;
  num? assetId;
  String? assetNumber;
  String? assetName;
  int? modelId;
  String? modelName;
  int? manufacturerId;
  String? manufacturerName;
  num? destSiteId;
  num? destBuildingId;
  num? destFloorId;
  num? destDepartmentId;
  num? destRoomId;
  num? senderSiteId;
  num? senderBuildingId;
  num? senderFloorId;
  num? senderDepartmentId;
  String? senderRoom;
  String? senderAssignedEmployeeId;
  num? senderMachineStatusId;
  int? senderMachineStatusValue;
  String? senderComment;
  String? comment;
  String? receiverEndUserId;
  String? receiverEndUserName;
  String? senderStartDate;
  String? senderEndDate;
  String? senderWorkingHours;
  String? senderTravelingHours;
  String? senderEngSignature;
  List<GenericAttachmentModel>? senderAttachments;
  List<GenericAttachmentModel>? attachments;
  List<GenericAttachmentModel>? assetTransferAttachments;
  String? receiverAssignedEmployeeId;
  String? receiverAssignedEmployeeNumber;
  num? receiverMachineStatusId;
  int? receiverMachineStatusValue;
  String? receiverComment;
  String? receiverStartDate;
  String? receiverEndDate;
  String? receiverWorkingHours;
  String? receiverTravelingHours;
  String? receiverEngSignature;
  List<GenericAttachmentModel>? receiverAttachments;
  num? supplierId;
  String? supplierName;
  String? destSiteName;
  String? destBuildingName;
  String? destFloorName;
  String? destDepartmentName;
  String? senderSiteName;
  String? senderBuildingName;
  String? senderFloorName;
  String? senderDepartmentName;
  String? senderAssignedEmployeeName;
  String? senderAssignedEmployeeNumber;
  String? senderMachineStatusName;
  String? senderEngSignatureUrl;
  String? receiverAssignedEmployeeName;
  String? receiverMachineStatusName;
  String? receiverEngSignatureUrl;
  bool? applied;
  bool? isSender;
  dynamic extensionNo;
  String? employeeId;
  String? name;
  String? createdDate;
  String? createdOn;
  String? modifiedOn;
  List<VisitTimers>? senderVisitTimers;
  List<VisitTimers>? receiverVisitTimers;
  List<VisitTimers>? assetTransferEngineerTimers;
  List<TimerModel>? timerModelList = [];
  List<AssistantEmployees>? assistantEmployees;
  List<AssetTransferAssistantEmployees>? assetTransferAssistantEmployeesSender = [];
  List<AssetTransferAssistantEmployees>? assetTransferAssistantEmployeesReceiver = [];
  List<AssetTransferContactPerson>? assetTransferContactPersons;
  AssetTransferAssistantEmployees? modelAssistantEmployees;
  List<AssetTransferAssistantEmployees>? assistantEmployList = [];
  TimerModel? tbsTimer = TimerModel();
  TimerModel? deviceTimePicker;

  DeviceTransfer copyWith(
          {num? id,
          num? transferNo,
          String? transferCode,
          Lookup? transferType,
          num? assetId,
          num? destSiteId,
          num? destBuildingId,
          num? destFloorId,
          num? destDepartmentId,
          num? destRoomId,
          num? senderSiteId,
          num? senderBuildingId,
          num? senderFloorId,
          num? senderDepartmentId,
          String? senderRoom,
          String? senderAssignedEmployeeId,
          num? senderMachineStatusId,
          String? senderComment,
          String? comment,
          String? receiverEndUserId,
          String? receiverEndUserName,
          String? senderStartDate,
          String? senderEndDate,
          String? senderWorkingHours,
          String? senderTravelingHours,
          String? senderEngSignature,
          List<GenericAttachmentModel>? senderAttachments,
          String? receiverAssignedEmployeeId,
          String? receiverAssignedEmployeeNumber,
          num? receiverMachineStatusId,
          String? receiverComment,
          String? receiverStartDate,
          String? receiverEndDate,
          String? receiverWorkingHours,
          String? receiverTravelingHours,
          String? receiverEngSignature,
          List<GenericAttachmentModel>? receiverAttachments,
          num? supplierId,
          String? supplierName,
          String? destSiteName,
          String? destBuildingName,
          String? destFloorName,
          String? destDepartmentNam,
          String? senderSiteName,
          String? senderBuildingName,
          String? senderFloorName,
          String? senderDepartmentName,
          String? senderAssignedEmployeeName,
          String? senderAssignedEmployeeNumber,
          String? senderMachineStatusName,
          String? senderEngSignatureUrl,
          String? receiverAssignedEmployeeName,
          String? receiverMachineStatusName,
          int? receiverMachineStatusValue,
          int? senderMachineStatusValue,
          String? receiverEngSignatureUrl,
          bool? applied,
          dynamic extensionNo,
          String? employeeId,
          String? name,
          String? createdDate,
          String? createdOn,
          String? modifiedOn,
          String? assetSerialNo,
          String? assetNumber,
          String? assetName,
          int? modelId,
          String? modelName,
          int? manufacturerId,
          String? manufacturerName,
          String? destDepartmentName,
          List<VisitTimers>? senderVisitTimers,
          List<VisitTimers>? receiverVisitTimers,
          List<AssetTransferAssistantEmployees>? assistantEmployList,
          TimerModel? tbsTimer,
          TimerModel? deviceTimePicker}) =>
      DeviceTransfer(
          id: id ?? this.id,
          transferNo: transferNo ?? this.transferNo,
          transferCode: transferCode ?? this.transferCode,
          transferType: transferType ?? this.transferType,
          assetId: assetId ?? this.assetId,
          destSiteId: destSiteId ?? this.destSiteId,
          destBuildingId: destBuildingId ?? this.destBuildingId,
          destFloorId: destFloorId ?? this.destFloorId,
          destDepartmentId: destDepartmentId ?? this.destDepartmentId,
          destRoomId: destRoomId ?? this.destRoomId,
          senderSiteId: senderSiteId ?? this.senderSiteId,
          senderBuildingId: senderBuildingId ?? this.senderBuildingId,
          senderFloorId: senderFloorId ?? this.senderFloorId,
          senderDepartmentId: senderDepartmentId ?? this.senderDepartmentId,
          senderRoom: senderRoom ?? this.senderRoom,
          senderAssignedEmployeeId: senderAssignedEmployeeId ?? this.senderAssignedEmployeeId,
          senderMachineStatusId: senderMachineStatusId ?? this.senderMachineStatusId,
          senderComment: senderComment ?? this.senderComment,
          comment: comment ?? this.comment,
          receiverEndUserId: receiverEndUserId ?? this.receiverEndUserId,
          receiverEndUserName: receiverEndUserName ?? this.receiverEndUserName,
          senderStartDate: senderStartDate ?? this.senderStartDate,
          senderEndDate: senderEndDate ?? this.senderEndDate,
          senderWorkingHours: senderWorkingHours ?? this.senderWorkingHours,
          senderTravelingHours: senderTravelingHours ?? this.senderTravelingHours,
          senderEngSignature: senderEngSignature ?? this.senderEngSignature,
          senderAttachments: senderAttachments ?? this.senderAttachments,
          receiverAssignedEmployeeId: receiverAssignedEmployeeId ?? this.receiverAssignedEmployeeId,
          receiverAssignedEmployeeNumber: receiverAssignedEmployeeNumber ?? this.receiverAssignedEmployeeNumber,
          receiverMachineStatusId: receiverMachineStatusId ?? this.receiverMachineStatusId,
          receiverComment: receiverComment ?? this.receiverComment,
          receiverStartDate: receiverStartDate ?? this.receiverStartDate,
          receiverEndDate: receiverEndDate ?? this.receiverEndDate,
          receiverWorkingHours: receiverWorkingHours ?? this.receiverWorkingHours,
          receiverTravelingHours: receiverTravelingHours ?? this.receiverTravelingHours,
          receiverEngSignature: receiverEngSignature ?? this.receiverEngSignature,
          receiverAttachments: receiverAttachments ?? this.receiverAttachments,
          supplierId: supplierId ?? this.supplierId,
          supplierName: supplierName ?? this.supplierName,
          destSiteName: destSiteName ?? this.destSiteName,
          destBuildingName: destBuildingName ?? this.destBuildingName,
          destFloorName: destFloorName ?? this.destFloorName,
          destDepartmentName: destDepartmentName ?? this.destDepartmentName,
          senderSiteName: senderSiteName ?? this.senderSiteName,
          senderBuildingName: senderBuildingName ?? this.senderBuildingName,
          senderFloorName: senderFloorName ?? this.senderFloorName,
          senderDepartmentName: senderDepartmentName ?? this.senderDepartmentName,
          senderAssignedEmployeeName: senderAssignedEmployeeName ?? this.senderAssignedEmployeeName,
          senderAssignedEmployeeNumber: senderAssignedEmployeeNumber ?? this.senderAssignedEmployeeNumber,
          senderMachineStatusName: senderMachineStatusName ?? this.senderMachineStatusName,
          senderMachineStatusValue: senderMachineStatusValue ?? this.senderMachineStatusValue,
          senderEngSignatureUrl: senderEngSignatureUrl ?? this.senderEngSignatureUrl,
          receiverAssignedEmployeeName: receiverAssignedEmployeeName ?? this.receiverAssignedEmployeeName,
          receiverMachineStatusName: receiverMachineStatusName ?? this.receiverMachineStatusName,
          receiverEngSignatureUrl: receiverEngSignatureUrl ?? this.receiverEngSignatureUrl,
          receiverMachineStatusValue: receiverMachineStatusValue ?? this.receiverMachineStatusValue,
          applied: applied ?? this.applied,
          extensionNo: extensionNo ?? this.extensionNo,
          employeeId: employeeId ?? this.employeeId,
          name: name ?? this.name,
          createdDate: createdDate ?? this.createdDate,
          createdOn: createdOn ?? this.createdOn,
          modifiedOn: modifiedOn ?? this.modifiedOn,
          assetSerialNo: assetSerialNo ?? this.assetSerialNo,
          assetNumber: assetNumber ?? this.assetNumber,
          assetName: assetName ?? this.assetName,
          modelId: modelId ?? this.modelId,
          modelName: modelName ?? this.modelName,
          manufacturerId: manufacturerId ?? this.manufacturerId,
          senderVisitTimers: senderVisitTimers ?? this.senderVisitTimers,
          receiverVisitTimers: receiverVisitTimers ?? this.receiverVisitTimers,
          tbsTimer: tbsTimer ?? this.tbsTimer,
          assistantEmployList: assistantEmployList ?? this.assistantEmployList,
          deviceTimePicker: deviceTimePicker ?? this.deviceTimePicker,
          manufacturerName: manufacturerName ?? this.manufacturerName);

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    map['transferNo'] = transferNo;
    map['transferCode'] = transferCode;
    map['assetId'] = assetId;
    map['destSiteId'] = destSiteId;
    map['destBuildingId'] = destBuildingId;
    map['destFloorId'] = destFloorId;
    map['destDepartmentId'] = destDepartmentId;
    map['destRoomId'] = destRoomId;
    map['senderSiteId'] = senderSiteId;
    map['senderBuildingId'] = senderBuildingId;
    map['senderFloorId'] = senderFloorId;
    map['senderDepartmentId'] = senderDepartmentId;
    map['senderRoom'] = senderRoom;
    map['senderAssignedEmployeeId'] = senderAssignedEmployeeId;
    map['senderMachineStatusId'] = senderMachineStatusId;
    map['senderComment'] = senderComment;
    map['comment'] = comment;
    map['receiverEndUserId'] = receiverEndUserId;
    map['receiverEndUserName'] = receiverEndUserName;
    map['senderStartDate'] = senderStartDate;
    map['senderEndDate'] = senderEndDate;
    map['senderWorkingHours'] = senderWorkingHours;
    map['senderTravelingHours'] = senderTravelingHours;
    map['senderEngSignature'] = senderEngSignature;
    if (senderVisitTimers != null) {
      map['assetTransferSenderTimers'] = senderVisitTimers!.map((v) => v.toJson()).toList();
    }
    if (receiverVisitTimers != null) {
      map['assetTransferReceiverTimers'] = receiverVisitTimers!.map((v) => v.toJson()).toList();
    }
    if (senderAttachments != null) {
      map['senderAttachments'] = senderAttachments!.map((v) => v.toAssetTransferJson()).toList();
    }
    map['receiverAssignedEmployeeId'] = receiverAssignedEmployeeId;
    map['receiverAssignedEmployeeNumber'] = receiverAssignedEmployeeNumber;
    map['receiverMachineStatusId'] = receiverMachineStatusId;
    map['receiverComment'] = receiverComment;
    map['receiverStartDate'] = receiverStartDate;
    map['receiverEndDate'] = receiverEndDate;
    map['receiverWorkingHours'] = receiverWorkingHours;
    map['receiverTravelingHours'] = receiverTravelingHours;
    map['receiverEngSignature'] = receiverEngSignature;
    if (receiverAttachments != null) {
      map['receiverAttachments'] = receiverAttachments?.map((v) => v.toAssetTransferJson() ?? {}).toList();
    }
    map["supplierId"] = supplierId;
    map["supplierName"] = supplierName;
    map["destSiteName"] = destSiteName;
    map["destBuildingName"] = destBuildingName;
    map["destFloorName"] = destFloorName;
    map["destDepartmentName"] = destDepartmentName;
    map["senderSiteName"] = senderSiteName;
    map["senderBuildingName"] = senderBuildingName;
    map["senderFloorName"] = senderFloorName;
    map["senderDepartmentName"] = senderDepartmentName;
    map["senderAssignedEmployeeName"] = senderAssignedEmployeeName;
    map["senderAssignedEmployeeNumber"] = senderAssignedEmployeeNumber;
    map["senderMachineStatusName"] = senderMachineStatusName;
    map["senderEngSignatureUrl"] = senderEngSignatureUrl;
    map["receiverAssignedEmployeeName"] = receiverAssignedEmployeeName;
    map["receiverMachineStatusName"] = receiverMachineStatusName;
    map["receiverEngSignatureUrl"] = receiverEngSignatureUrl;
    map["applied"] = applied;
    map["extensionNo"] = extensionNo;
    map["employeeId"] = employeeId;
    map["name"] = name;
    map["createdDate"] = createdDate;
    map["createdOn"] = createdOn;
    map["modifiedOn"] = modifiedOn;
    map["assetSerialNo"] = assetSerialNo;
    map["assetNumber"] = assetNumber;
    map["assetName"] = assetName;
    map["modelId"] = modelId;
    map["modelName"] = modelName;
    map["manufacturerId"] = manufacturerId;
    map["manufacturerName"] = manufacturerName;
    return map;
  }

  Map<String, dynamic> toCreateAssetTransferJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    map['assetId'] = assetId;
    map['transferTypeId'] = transferType?.id;
    map['destSiteId'] = destSiteId;
    map['destSiteId'] = destSiteId;
    map['destBuildingId'] = destBuildingId;
    map['destFloorId'] = destFloorId;
    map['destDepartmentId'] = destDepartmentId;
    map['destRoomId'] = destRoomId;
    map['comment'] = comment;
    if (attachments != null) {
      map['attachments'] = attachments!.map((v) => v.toAssetTransferJson()).toList();
    }
    return map;
  }

  Map<String, dynamic> toEngineerUpdateJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    map['statusValue'] = statusValue;
    map['isSender'] = isSender;
    map['techComment'] = isSender! ? senderComment : receiverComment;
    map['nurseSignature'] = nurseSignature;
    map['assetTransferAssistantEmployees'] = modelAssistantEmployees;
    map['assetTransferEngineerTimers'] = assetTransferEngineerTimers;
    if (attachments != null) {
      map['attachments'] = attachments!.map((v) => v.toAssetTransferJson()).toList();
    }
    if (assetTransferEngineerTimers != null) {
      map['assetTransferEngineerTimers'] = assetTransferEngineerTimers!.map((v) => v.toJson()).toList();
    }
    if (assistantEmployList != null && assistantEmployList!.isNotEmpty) {
      map['assetTransferAssistantEmployees'] = assistantEmployList;
    } else {
      map['assetTransferAssistantEmployees'] = [];
    }
    // if (modelAssistantEmployees != null) {
    //   if (modelAssistantEmployees!.employeeId != null) {
    //     map['assetTransferAssistantEmployees'] = [modelAssistantEmployees!.toJson()];
    //   } else {
    //     map['assetTransferAssistantEmployees'] = [];
    //   }
    // }
    return map;
  }

  Map<String, dynamic> transferBody({Asset? asset}) {
    final map = <String, dynamic>{};
    map['id'] = 0;
    map['transferNo'] = transferNo;
    map['transferCode'] = transferCode;
    map['assetId'] = asset?.id;
    map['destSiteId'] = destSiteId;
    map['destBuildingId'] = destBuildingId;
    map['destFloorId'] = destFloorId;
    map['destDepartmentId'] = destDepartmentId;
    map['destRoomId'] = destRoomId;
    map['senderSiteId'] = asset?.site?.id;
    map['senderBuildingId'] = asset?.building?.id;
    map['senderFloorId'] = asset?.floor?.id;
    map['senderDepartmentId'] = asset?.department?.id;
    map['senderRoom'] = asset?.room;
    map['senderAssignedEmployeeId'] = senderAssignedEmployeeId;
    map['senderMachineStatusId'] = senderMachineStatusId;
    map['senderComment'] = senderComment;
    map['comment'] = comment;
    map['receiverEndUserId'] = receiverEndUserId;
    map['receiverEndUserName'] = receiverEndUserName;
    map['senderStartDate'] = senderStartDate;
    map['senderEndDate'] = senderEndDate;
    map['senderWorkingHours'] = senderWorkingHours;
    map['senderTravelingHours'] = senderTravelingHours;
    map['senderEngSignature'] = senderEngSignature;
    if (senderAttachments != null) {
      map['senderAttachments'] = senderAttachments!.map((v) => v.toAssetTransferJson()).toList();
    }
    if (senderVisitTimers != null) {
      map['assetTransferSenderTimers'] = senderVisitTimers!.map((v) => v.toJson()).toList();
    }
    if (receiverVisitTimers != null) {
      map['assetTransferReceiverTimers'] = receiverVisitTimers!.map((v) => v.toJson()).toList();
    }
    map['receiverAssignedEmployeeId'] = receiverAssignedEmployeeId;
    map['receiverAssignedEmployeeNumber'] = receiverAssignedEmployeeNumber;
    map['receiverMachineStatusId'] = receiverMachineStatusId;
    map['receiverComment'] = receiverComment;
    map['receiverStartDate'] = receiverStartDate;
    map['receiverEndDate'] = receiverEndDate;
    map['receiverWorkingHours'] = receiverWorkingHours;
    map['receiverTravelingHours'] = receiverTravelingHours;
    map['receiverEngSignature'] = receiverEngSignature;
    if (receiverAttachments != null) {
      map['receiverAttachments'] = receiverAttachments!.map((v) => v.toAssetTransferJson() ?? {}).toList();
    }
    return map;
  }

  fromDetails(DeviceTransfer? assetTransfer) {
    if (assetTransfer == null) return;
    id = assetTransfer.id;
    transferNo = assetTransfer.transferNo;
    transferType = assetTransfer.transferType;
    transferCode = assetTransfer.transferCode;
    assetId = assetTransfer.assetId;
    destSiteId = assetTransfer.destSiteId;
    destBuildingId = assetTransfer.destBuildingId;
    destFloorId = assetTransfer.destFloorId;
    destDepartmentId = assetTransfer.destDepartmentId;
    destRoomId = assetTransfer.destRoomId;
    senderSiteId = assetTransfer.senderSiteId;
    senderBuildingId = assetTransfer.senderBuildingId;
    senderFloorId = assetTransfer.senderFloorId;
    senderDepartmentId = assetTransfer.senderDepartmentId;
    senderRoom = assetTransfer.senderRoom;
    senderAssignedEmployeeId = assetTransfer.senderAssignedEmployeeId;
    senderMachineStatusId = assetTransfer.senderMachineStatusId;
    senderComment = assetTransfer.senderComment;
    comment = assetTransfer.comment;
    receiverEndUserId = assetTransfer.receiverEndUserId;
    receiverEndUserName = assetTransfer.receiverEndUserName;
    senderStartDate = assetTransfer.senderStartDate;
    senderEndDate = assetTransfer.senderEndDate;
    senderWorkingHours = assetTransfer.senderWorkingHours;
    senderTravelingHours = assetTransfer.senderTravelingHours;
    senderEngSignature = assetTransfer.senderEngSignature;
    senderAttachments = assetTransfer.senderAttachments;
    receiverAssignedEmployeeId = assetTransfer.receiverAssignedEmployeeId;
    receiverAssignedEmployeeNumber = assetTransfer.receiverAssignedEmployeeNumber;
    receiverMachineStatusId = assetTransfer.receiverMachineStatusId;
    receiverComment = assetTransfer.receiverComment;
    receiverStartDate = assetTransfer.receiverStartDate;
    receiverEndDate = assetTransfer.receiverEndDate;
    receiverWorkingHours = assetTransfer.receiverWorkingHours;
    receiverTravelingHours = assetTransfer.receiverTravelingHours;
    receiverEngSignature = assetTransfer.receiverEngSignature;
    receiverAttachments = assetTransfer.receiverAttachments;
    supplierId = assetTransfer.supplierId;
    supplierName = assetTransfer.supplierName;
    destSiteName = assetTransfer.destSiteName;
    destBuildingName = assetTransfer.destBuildingName;
    destFloorName = assetTransfer.destFloorName;
    destDepartmentName = assetTransfer.destDepartmentName;
    senderSiteName = assetTransfer.senderSiteName;
    senderBuildingName = assetTransfer.senderBuildingName;
    senderFloorName = assetTransfer.senderFloorName;
    senderDepartmentName = assetTransfer.senderDepartmentName;
    senderAssignedEmployeeName = assetTransfer.senderAssignedEmployeeName;
    senderAssignedEmployeeNumber = assetTransfer.senderAssignedEmployeeNumber;
    senderMachineStatusName = assetTransfer.senderMachineStatusName;
    senderEngSignatureUrl = assetTransfer.senderEngSignatureUrl;
    receiverAssignedEmployeeName = assetTransfer.receiverAssignedEmployeeName;
    receiverMachineStatusName = assetTransfer.receiverMachineStatusName;
    receiverEngSignatureUrl = assetTransfer.receiverEngSignatureUrl;
    applied = assetTransfer.applied;
    extensionNo = assetTransfer.extensionNo;
    employeeId = assetTransfer.employeeId;
    name = assetTransfer.name;
    createdDate = assetTransfer.createdDate;
    createdOn = assetTransfer.createdOn;
    modifiedOn = assetTransfer.modifiedOn;
    assetSerialNo = assetTransfer.assetSerialNo;
    assetNumber = assetTransfer.assetNumber;
    assetName = assetTransfer.assetName;
    modelId = assetTransfer.modelId;
    modelName = assetTransfer.modelName;
    manufacturerId = assetTransfer.manufacturerId;
    manufacturerName = assetTransfer.manufacturerName;
    senderVisitTimers = assetTransfer.senderVisitTimers;
    receiverVisitTimers = assetTransfer.receiverVisitTimers;
    assetTransferAttachments = assetTransfer.assetTransferAttachments;
    assetTransferAssistantEmployeesReceiver = assetTransfer.assetTransferAssistantEmployeesReceiver;
    assetTransferAssistantEmployeesSender = assetTransfer.assetTransferAssistantEmployeesSender;
    senderMachineStatusValue = assetTransfer.senderMachineStatusValue;
    receiverMachineStatusValue = assetTransfer.receiverMachineStatusValue;
    assetTransferContactPersons = assetTransfer.assetTransferContactPersons;
  }
//
// Future<bool> validate(BuildContext context) async {
//   if (assetId == null) {
//     await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.device}");
//     return false;
//   } else if (destSiteId == null) {
//     await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.destinationSite}");
//     return false;
//   } else if (destBuildingId == null) {
//     await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.building}");
//     return false;
//   } else if (destFloorId == null) {
//     await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.floor}");
//     return false;
//   } else if (destDepartmentId == null) {
//     await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.department}");
//     return false;
//   }
//   return true;
// }
}

class AssetTransferAssistantEmployees {
  DateTime? startDate;
  DateTime? endDate;
  double? workingHours;
  String? techComment;
  String? employeeId;
  String? employeeNumber;
  String? employeeName;
  String? email;
  String? mobileNo;
  dynamic extension;

  AssetTransferAssistantEmployees(
      {this.startDate, this.endDate, this.workingHours, this.techComment, this.employeeId, this.employeeName, this.employeeNumber, this.email, this.extension, this.mobileNo});

  AssetTransferAssistantEmployees.fromJson(Map<String, dynamic> json) {
    startDate = json['startDate'] != null ? DateTime.parse(json['startDate']) : null;
    endDate = json['endDate'] != null ? DateTime.parse(json['endDate']) : null;
    workingHours = json['workingHours'];
    techComment = json['techComment'];
    employeeId = json['employeeId'];
    employeeNumber = json['employeeNumber'];
    employeeName = json['employeeName'];
    email = json['email'];
    mobileNo = json['mobileNo'];
    extension = json['extension'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['startDate'] = startDate?.toIso8601String();
    data['endDate'] = endDate?.toIso8601String();
    data['workingHours'] = workingHours;
    data['techComment'] = techComment;
    data['employeeId'] = employeeId;
    return data;
  }
}

class AssetTransferContactPerson {
  int? id;
  String? employeeId;
  String? employeeNumber;
  String? employeeName;
  String? email;
  String? mobileNo;
  String? extension;

  AssetTransferContactPerson({
    this.id,
    this.employeeId,
    this.employeeNumber,
    this.employeeName,
    this.email,
    this.mobileNo,
    this.extension,
  });

  factory AssetTransferContactPerson.fromJson(Map<String, dynamic> json) {
    return AssetTransferContactPerson(
      id: json['id'],
      employeeId: json['employeeId'],
      employeeNumber: json['employeeNumber'],
      employeeName: json['employeeName'],
      email: json['email'],
      mobileNo: json['mobileNo'],
      extension: json['extension'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'employeeId': employeeId,
      'employeeNumber': employeeNumber,
      'employeeName': employeeName,
      'email': email,
      'mobileNo': mobileNo,
      'extension': extension,
    };
  }
}
