import 'package:flutter/foundation.dart';
import 'package:test_sa/models/fault_description.dart';
import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/models/helper_data_models/spare_part/activity_spare_part_model.dart';
import 'package:test_sa/models/helper_data_models/workorder/work_order_helper_models.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/new_models/assistant_employee.dart';

class WorkOrderDetail {
  WorkOrderDetail({
    required this.data,
    required this.message,
    required this.title,
    required this.innerMessage,
    required this.responseCode,
    required this.isSuccess,
  });

  final WorkOrderData? data;
  final String? message;
  final dynamic title;
  final dynamic innerMessage;
  final int? responseCode;
  final bool? isSuccess;

  factory WorkOrderDetail.fromJsonCons(Map<String, dynamic> json) {
    return WorkOrderDetail(
      data: json["data"] == null ? null : WorkOrderData.fromJson(json["data"]),
      message: json["message"],
      title: json["title"],
      innerMessage: json["innerMessage"],
      responseCode: json["responseCode"],
      isSuccess: json["isSuccess"],
    );
  }

  static Future<WorkOrderDetail> fromJson(Map<String, dynamic> json) {
    return compute(WorkOrderDetail.fromJsonCons, json);
  }

  Map<String, dynamic> toJson() => {
        "data": data?.toJson(),
        "message": message,
        "title": title,
        "innerMessage": innerMessage,
        "responseCode": responseCode,
        "isSuccess": isSuccess,
      };
}

class WorkOrderData {
  WorkOrderData({
    this.requestId,
    required this.workOrderNo,
    required this.workOrderCreatedBy,
    required this.requestedDate,
    required this.asset,
    required this.assetGroup,
    required this.manufacturer,
    required this.model,
    required this.assetNdModel,
    required this.site,
    required this.building,
    required this.floor,
    required this.department,
    required this.room,
    required this.assetType,
    required this.assignedEmployee,
    required this.lastActivityStatus,
    required this.status,
    required this.setReminder,
    required this.nextStep,
    required this.assetVerificationType,
    required this.workOrderContactPerson,
    required this.equipmentStatus,
    required this.priority,
    required this.requestedThrough,
    required this.typeofRequest,
    required this.loanAvailablity,
    required this.assetLoan,
    required this.safety,
    required this.problemDescription,
    required this.faultDescription,
    required this.comments,
    required this.voiceNote,
    required this.workOrderAttachments,
    required this.returnToService,
    required this.serviceType,
    required this.failureReasone,
    required this.solution,
    required this.totalWorkingHours,
    this.needAVisitComment,
    this.needAVisitDateTime,
    this.iHaveArrivedDate,
    this.rejectReason,
    this.closedDate,
    this.since,
    this.cmFrame,
    this.edd,
    this.rejectComment,
    this.callResponse,
    this.descriptionOfFinding,
    this.actionTaken,
    this.labourCost,
    this.sparePartCost,
    this.travelCost,
    this.qAmount,
    this.prNo,
    this.poNo,
    this.mrNo,
    this.exchangeCost,
    required this.workOrderHistory,
    required this.activities,
    required this.activityAssetToBeRetireds,
    this.itgFormWorkOrderStatus,
  });

  int? requestId;
  String? workOrderNo;
  WorkOrderAssignedEmployee? workOrderCreatedBy;
  DateTime? requestedDate;
  WorkOrderAsset? asset;
  Lookup? assetGroup;
  Lookup? manufacturer;
  Lookup? model;
  Lookup? assetNdModel;
  WorkOrderSite? site;
  Lookup? building;
  Lookup? floor;
  AssetGroup? department;
  Lookup? room;
  Lookup? assetType;
  WorkOrderAssignedEmployee? assignedEmployee;
  Lookup? lastActivityStatus;
  Lookup? status;
  Lookup? setReminder;
  Lookup? nextStep;
  int? assetVerificationType;
  List<WorkOrderContactPerson> workOrderContactPerson;
  Lookup? equipmentStatus;
  Lookup? priority;
  Lookup? requestedThrough;
  Lookup? typeofRequest;
  Lookup? loanAvailablity;
  AssetLoan? assetLoan;
  Lookup? safety;
  Lookup? problemDescription;
  String? comments;
  String? voiceNote;
  List<GenericAttachmentModel> workOrderAttachments;
  String? returnToService;
  Lookup? serviceType;
  Lookup? failureReasone;
  FaultDescription? faultDescription;
  String? solution;
  String? edd;
  Lookup? cmFrame;

  //cmComments
  String? totalWorkingHours;
  DateTime? needAVisitDateTime;
  String? needAVisitComment;
  String? iHaveArrivedDate;
  String? closedDate;
  Lookup? rejectReason;
  String? rejectComment;
  String? callResponse;
  String? descriptionOfFinding;
  String? actionTaken;
  int? since;
  num? sparePartCost;
  num? labourCost;
  num? travelCost;
  num? qAmount;
  String? prNo;
  String? poNo;
  String? mrNo;
  num? exchangeCost;
  List<WorkOrderHistory> workOrderHistory;
  List<Activities> activities;
  List<dynamic> activityAssetToBeRetireds;
  String? itgFormWorkOrderStatus;

  factory WorkOrderData.fromJson(Map<String, dynamic> json) {
    return WorkOrderData(
      requestId: json["id"],
      workOrderNo: json["workOrderNo"],
      workOrderCreatedBy: json["workOrderCreatedBy"] == null ? null : WorkOrderAssignedEmployee.fromJson(json["workOrderCreatedBy"]),
      requestedDate: DateTime.tryParse(json["requestedDate"] ?? ""),
      asset: json["asset"] == null ? null : WorkOrderAsset.fromJson(json["asset"]),
      assetGroup: json["assetGroup"] == null ? null : Lookup.fromJson(json["assetGroup"]),
      manufacturer: json["manufacturer"] == null ? null : Lookup.fromJson(json["manufacturer"]),
      model: json["model"] == null ? null : Lookup.fromJson(json["model"]),
      assetNdModel: json["assetNDModel"] == null ? null : Lookup.fromJson(json["assetNDModel"]),
      site: json["site"] == null ? null : WorkOrderSite.fromJson(json["site"]),
      building: json["building"] == null ? null : Lookup.fromJson(json["building"]),
      floor: json["floor"] == null ? null : Lookup.fromJson(json["floor"]),
      department: json["department"] == null ? null : AssetGroup.fromJson(json["department"]),
      room: json["room"] == null ? null : Lookup.fromJson(json["room"]),
      rejectComment: json["rejectComment"],
      callResponse: json["callResponse"],
      descriptionOfFinding: json["descriptionOfFinding"],
      actionTaken: json["actionTaken"],
      iHaveArrivedDate: json["iHaveArrivedDate"],
      closedDate: json["closedDate"],
      cmFrame: json["cmFrame"] == null ? null : Lookup.fromJson(json["cmFrame"]),
      rejectReason: json["rejectReason"] == null ? null : Lookup.fromJson(json["rejectReason"]),
      since: json['since'],
      travelCost: json['travelCost'],
      sparePartCost: json['sparePartCost'],
      labourCost: json['laborCost'],
      qAmount: json['qAmount'],
      prNo: json['prNo'],
      poNo: json['poNo'],
      mrNo: json['mrNo'],
      exchangeCost: json['exchangeCost'],
      assetType: json["assetType"] == null ? null : Lookup.fromJson(json["assetType"]),
      assignedEmployee: json["assignedEmployee"] == null ? null : WorkOrderAssignedEmployee.fromJson(json["assignedEmployee"]),
      lastActivityStatus: json["lastActivityStatus"] != null ? Lookup.fromJson(json["lastActivityStatus"]) : null,
      status: json["status"] == null ? null : Lookup.fromJson(json["status"]),
      setReminder: json["setReminder"] == null ? null : Lookup.fromJson(json["setReminder"]),
      nextStep: json["nextStep"] == null ? null : Lookup.fromJson(json["nextStep"]),
      assetVerificationType: json["assetVerificationType"],
      workOrderContactPerson: json["workOrderContactPerson"] == null ? [] : List<WorkOrderContactPerson>.from(json["workOrderContactPerson"]!.map((x) => WorkOrderContactPerson.fromJson(x))),
      equipmentStatus: json["equipmentStatus"] == null ? null : Lookup.fromJson(json["equipmentStatus"]),
      priority: json["priority"] == null ? null : Lookup.fromJson(json["priority"]),
      requestedThrough: json["requestedThrough"] == null ? null : Lookup.fromJson(json["requestedThrough"]),
      typeofRequest: json["typeofRequest"] == null ? null : Lookup.fromJson(json["typeofRequest"]),
      loanAvailablity: json["loanAvailablity"] == null ? null : Lookup.fromJson(json["loanAvailablity"]),
      assetLoan: json["assetLoan"] == null ? null : AssetLoan.fromJson(json["assetLoan"]),
      safety: json["safety"] == null ? null : Lookup.fromJson(json["safety"]),
      problemDescription: json["problemDescription"] == null ? null : Lookup.fromJson(json["problemDescription"]),
      comments: json["comments"],
      voiceNote: json["voiceNote"],
      edd: json["edd"],
      workOrderAttachments: json["workOrderAttachments"] == null ? [] : List.from(json['workOrderAttachments']).map((e) => GenericAttachmentModel.fromWorkOrderJson(e)).toList(),
      returnToService: json["returnToService"],
      serviceType: json["serviceType"] == null ? null : Lookup.fromJson(json["serviceType"]),
      failureReasone: json["failureReasone"] == null ? null : Lookup.fromJson(json["failureReasone"]),
      faultDescription: json["faultDescription"] == null ? null : FaultDescription.fromJson(json["faultDescription"]),
      solution: json["solution"],
      totalWorkingHours: (json["totalWorkingHours"] ?? "").toString(),
      workOrderHistory: json["workOrderHistory"] == null ? [] : List<WorkOrderHistory>.from(json["workOrderHistory"]!.map((x) => WorkOrderHistory.fromJson(x))),
      activities: json["activities"] == null ? [] : List<Activities>.from(json["activities"]!.map((x) => Activities.fromJson(x))),
      needAVisitDateTime: DateTime.tryParse(json["needAVisitDateTime"] ?? ""),
      needAVisitComment: json["needAVisitComment"],
      itgFormWorkOrderStatus: json["itgFormWorkOrderStatus"],
      activityAssetToBeRetireds: json["activityAssetToBeRetireds"] == null ? [] : List<dynamic>.from(json["activityAssetToBeRetireds"]!.map((x) => x)),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": requestId,
        "workOrderNo": workOrderNo,
        "workOrderCreatedBy": workOrderCreatedBy?.toJson(),
        "requestedDate": requestedDate?.toIso8601String(),
        "needAVisitDateTime": needAVisitDateTime?.toIso8601String(),
        "asset": asset?.toJson(),
        "assetGroup": assetGroup?.toJson(),
        "manufacturer": manufacturer?.toJson(),
        "model": model?.toJson(),
        "assetNDModel": assetNdModel?.toJson(),
        "site": site?.toJson(),
        "building": building?.toJson(),
        "floor": floor?.toJson(),
        "department": department?.toJson(),
        "room": room?.toJson(),
        "assetType": assetType?.toJson(),
        "assignedEmployee": assignedEmployee?.toJson(),
        "lastActivityStatus": lastActivityStatus,
        "status": status?.toJson(),
        "setReminder": setReminder?.toJson(),
        "nextStep": nextStep?.toJson(),
        "assetVerificationType": assetVerificationType,
        "workOrderContactPerson": workOrderContactPerson.map((x) => x?.toJson()).toList(),
        "equipmentStatus": equipmentStatus?.toJson(),
        "priority": priority?.toJson(),
        "requestedThrough": requestedThrough?.toJson(),
        "typeofRequest": typeofRequest?.toJson(),
        "loanAvailablity": loanAvailablity?.toJson(),
        "assetLoan": assetLoan?.toJson(),
        "cmFrame": cmFrame?.toJson(),
        "safety": safety?.toJson(),
        "problemDescription": problemDescription?.toJson(),
        "comments": comments,
        "voiceNote": voiceNote,
        "edd": edd,
        'mrNo': mrNo,
        'exchangeCost': exchangeCost,
        "workOrderAttachments": workOrderAttachments.map((e) => e.toWorkOrderJson() ?? {}).toList(),
        "returnToService": returnToService,
        "serviceType": serviceType?.toJson(),
        "failureReasone": failureReasone?.toJson(),
        "solution": solution,
        "totalWorkingHours": totalWorkingHours,
        "workOrderHistory": workOrderHistory.map((x) => x.toJson()).toList(),
        "activities": activities.map((x) => x.toJson()).toList(),
        "activityAssetToBeRetireds": activityAssetToBeRetireds.map((x) => x).toList(),
        "itgFormWorkOrderStatus": itgFormWorkOrderStatus,
      };
}

class WorkOrderAsset {
  WorkOrderAsset({
    required this.id,
    required this.assetNumber,
    required this.assetSerialNo,
    required this.hasTrainingImageData,
  });

  int? id;
  String? assetNumber;
  String? assetSerialNo;
  bool? hasTrainingImageData;

  factory WorkOrderAsset.fromJson(Map<String, dynamic> json) {
    return WorkOrderAsset(
      id: json["id"],
      assetNumber: json["assetNumber"],
      assetSerialNo: json["assetSerialNo"],
      hasTrainingImageData: json["hasTrainingImageData"],
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "assetNumber": assetNumber,
        "assetSerialNo": assetSerialNo,
        "hasTrainingImageData": hasTrainingImageData,
      };
}

class AssetGroup {
  AssetGroup({
    required this.id,
    required this.name,
  });

  int? id;
  String? name;

  factory AssetGroup.fromJson(Map<String, dynamic> json) {
    return AssetGroup(
      id: json["id"],
      name: json["name"],
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
      };
}

class WorkOrderAssignedEmployee {
  String? userId;
  String? userName;
  String? email;
  String? employeeId;
  int? languageId;
  String? extensionNo;
  String? phoneNumber;
  String? positionName;
  String? position;
  bool? isActive;

  WorkOrderAssignedEmployee({this.userId, this.userName, this.email, this.employeeId, this.languageId, this.extensionNo, this.phoneNumber, this.positionName, this.position, this.isActive});

  WorkOrderAssignedEmployee.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    userName = json['userName'];
    email = json['email'];
    employeeId = json['employeeId'];
    languageId = json['languageId'];
    extensionNo = json['extensionNo'];
    phoneNumber = json['phoneNumber'];
    positionName = json['positionName'];
    position = json['position'];
    isActive = json['isActive'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['userId'] = this.userId;
    data['userName'] = this.userName;
    data['email'] = this.email;
    data['employeeId'] = this.employeeId;
    data['languageId'] = this.languageId;
    data['extensionNo'] = this.extensionNo;
    data['phoneNumber'] = this.phoneNumber;
    data['positionName'] = this.positionName;
    data['position'] = this.position;
    data['isActive'] = this.isActive;
    return data;
  }
}

class AssetLoan {
  AssetLoan({
    required this.id,
    required this.assetSerialNo,
    required this.tagCode,
    required this.systemId,
    required this.assetNumber,
    required this.assetName,
  });

  dynamic id;
  dynamic tagCode;
  dynamic systemId;
  String? assetSerialNo;
  String? assetNumber;
  String? assetName;

  factory AssetLoan.fromJson(Map<String, dynamic> json) {
    return AssetLoan(
      id: json["id"],
      tagCode: json["tagCode"],
      systemId: json["systemId"],
      assetSerialNo: json["assetSerialNo"],
      assetNumber: json["assetNumber"],
      assetName: json["assetName"],
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "assetName": assetName,
        "assetNumber": assetNumber,
        "assetSerialNo": assetSerialNo,
        "tagCode": tagCode,
        "systemId": systemId,
      };
}

class Activities {
  int? id;
  int? orderNo;
  Lookup? activityStatus;
  ActivityMaintenance? activityMaintenance;
  ActivitySparePart? activitySparePart;
  String? activityType;

  Activities({this.id, this.orderNo, this.activityStatus, this.activityMaintenance, this.activityType, this.activitySparePart});

  Activities.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    orderNo = json['orderNo'];
    activityStatus = json['activityStatus'] != null ? Lookup.fromJson(json['activityStatus']) : null;
    activityMaintenance = json['activityMaintenance'] != null ? ActivityMaintenance.fromJson(json['activityMaintenance']) : null;
    if (activityMaintenance != null) {
      activityType = 'CM Activity';
    }

    activitySparePart = json['activitySparePart'] != null ? ActivitySparePart.fromJson(json['activitySparePart']) : null;
    if (activitySparePart != null) {
      activityType = 'Spare Part Request';
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['orderNo'] = orderNo;
    if (activityStatus != null) {
      data['activityStatus'] = activityStatus!.toJson();
    }
    if (activitySparePart != null) {
      data['activitySparePart'] = activitySparePart!.toJson();
    }
    if (activityMaintenance != null) {
      data['activityMaintenance'] = activityMaintenance!.toJson();
    }
    return data;
  }
}

class ActivityStatus {
  int? id;
  String? name;
  int? value;

  ActivityStatus({this.id, this.name, this.value});

  ActivityStatus.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    value = json['value'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['value'] = value;
    return data;
  }
}

class ActivitySparePart {
  int? id;
  PartCatalogItem? partCatalogItem;
  double? quantity;
  double? installQty;
  double? returnQty;
  String? comment;
  List<GenericAttachmentModel>? acitiySparePartAttachments;

  ActivitySparePart({this.id, this.partCatalogItem, this.quantity, this.installQty, this.returnQty, this.comment, this.acitiySparePartAttachments});

  ActivitySparePart.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    partCatalogItem = json['partCatalogItem'] != null ? new PartCatalogItem.fromJson(json['partCatalogItem']) : null;
    quantity = json['quantity'];
    installQty = json['installQty'];
    returnQty = json['returnQty'];
    comment = json['comment'];
    if (json['acitiySparePartAttachments'] != null) {
      acitiySparePartAttachments = <GenericAttachmentModel>[];
      json['acitiySparePartAttachments'].forEach((v) {
        acitiySparePartAttachments!.add(GenericAttachmentModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    if (partCatalogItem != null) {
      data['partCatalogItem'] = partCatalogItem!.toJson();
    }
    data['quantity'] = quantity;
    data['installQty'] = installQty;
    data['returnQty'] = returnQty;
    data['comment'] = comment;
    if (acitiySparePartAttachments != null) {
      data['acitiySparePartAttachments'] = acitiySparePartAttachments!.map((v) => v?.toJson() ?? {}).toList();
    }
    return data;
  }
}

class PartCatalogItem {
  int? id;
  String? partName;
  String? partNumber;
  String? oracleCode;

  PartCatalogItem({this.id, this.partName, this.partNumber, this.oracleCode});

  PartCatalogItem.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    partName = json['partName'];
    partNumber = json['partNumber'];
    oracleCode = json['oracleCode'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['partName'] = this.partName;
    data['partNumber'] = this.partNumber;
    return data;
  }
}

class WorkOrderSite {
  WorkOrderSite({
    required this.id,
    required this.siteName,
  });

  int? id;
  String? siteName;

  factory WorkOrderSite.fromJson(Map<String, dynamic> json) {
    return WorkOrderSite(
      id: json["id"],
      siteName: json["siteName"],
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "siteName": siteName,
      };
}

class WorkOrderContactPerson {
  WorkOrderContactPerson({
    required this.id,
    required this.name,
    required this.employeeId,
    required this.position,
    required this.extension,
    required this.email,
    required this.mobilePhone,
    required this.contactUser,
  });

  int? id;
  String? name;
  String? employeeId;
  String? position;
  String? extension;
  String? email;
  String? mobilePhone;
  WorkOrderAssignedEmployee? contactUser;

  factory WorkOrderContactPerson.fromJson(Map<String, dynamic> json) {
    return WorkOrderContactPerson(
      id: json["id"],
      name: json["name"],
      employeeId: json["employeeId"],
      position: json["position"],
      extension: json["extension"],
      email: json["email"],
      mobilePhone: json["mobilePhone"],
      contactUser: json["contactUser"] == null ? null : WorkOrderAssignedEmployee.fromJson(json["contactUser"]),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
        "employeeId": employeeId,
        "position": position,
        "extension": extension,
        "email": email,
        "mobilePhone": mobilePhone,
        "contactUser": contactUser?.toJson(),
      };
}

class WorkOrderHistory {
  WorkOrderHistory({
    required this.id,
    required this.workorderStatus,
    this.assetVerificationType,
    this.photoVerfication,
    required this.activityStatus,
    required this.date,
    required this.timeDifference,
    required this.user,
    required this.step,
    required this.fixRemotlyStartTime,
    required this.fixRemotlyEndTime,
    required this.fixRemotlyWorkingHours,
    required this.comments,
    required this.needAVisitDateTime,
  });

  int? id;
  Lookup? workorderStatus;
  Lookup? assetVerificationType;
  Lookup? activityStatus;
  DateTime? date;
  String timeDifference = '';
  String? photoVerfication;
  WorkOrderAssignedEmployee? user;
  Lookup? step;
  DateTime? fixRemotlyStartTime;
  DateTime? fixRemotlyEndTime;
  num? fixRemotlyWorkingHours;
  String? comments;
  DateTime? needAVisitDateTime;

  factory WorkOrderHistory.fromJson(Map<String, dynamic> json) {
    return WorkOrderHistory(
      id: json["id"],
      workorderStatus: json["workorderStatus"] == null ? null : Lookup.fromJson(json["workorderStatus"]),
      assetVerificationType: json["assetVerificationType"] == null ? null : Lookup.fromJson(json["assetVerificationType"]),
      activityStatus: json["activityStatus"] == null ? null : Lookup.fromJson(json["activityStatus"]),
      photoVerfication: json["photoVerfication"],
      date: DateTime.tryParse(json["date"] ?? ""),
      user: json["user"] == null ? null : WorkOrderAssignedEmployee.fromJson(json["user"]),
      step: json["step"] == null ? null : Lookup.fromJson(json["step"]),
      fixRemotlyStartTime: DateTime.tryParse(json["fixRemotlyStartTime"] ?? ""),
      fixRemotlyEndTime: DateTime.tryParse(json["fixRemotlyEndTime"] ?? ""),
      fixRemotlyWorkingHours: json["fixRemotlyWorkingHours"],
      timeDifference: '',
      comments: json["comments"],
      needAVisitDateTime: DateTime.tryParse(json["needAVisitDateTime"] ?? ""),
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "workorderStatus": workorderStatus?.toJson(),
        "assetVerificationType": assetVerificationType?.toJson(),
        "photoVerfication": photoVerfication,
        "activityStatus": activityStatus?.toJson(),
        "date": date?.toIso8601String(),
        "user": user?.toJson(),
        "step": step?.toJson(),
        "fixRemotlyStartTime": fixRemotlyStartTime?.toIso8601String(),
        "fixRemotlyEndTime": fixRemotlyEndTime?.toIso8601String(),
        "fixRemotlyWorkingHours": fixRemotlyWorkingHours,
        "comments": comments,
        "needAVisitDateTime": needAVisitDateTime?.toIso8601String(),
      };
}

class ActivityMaintenance {
  int? id;
  ActivityStatus? activityStatus;
  String? startTime;
  Lookup? lastSituation;
  String? endTime;
  double? workingHours;
  double? travelHours;
  Lookup? repairLocation;
  AssignedEmployee? assignedEmployee;
  String? technicalComment;
  Lookup? supplier;
  Lookup? supplierEngineer;
  String? supplierStartTime;
  String? supplierEndTime;
  double? supplierWorkingHours;
  String? activityType;
  List<AssistantEmployeesModel>? assistantEmployees;
  List<ActivityMaintenanceTimers>? activityMaintenanceTimers;

  ActivityMaintenance(
      {this.id,
      this.activityStatus,
      this.lastSituation,
      this.startTime,
      this.endTime,
      this.workingHours,
      this.travelHours,
      this.repairLocation,
      this.assignedEmployee,
      this.activityMaintenanceTimers,
      this.technicalComment,
      this.supplier,
      this.supplierEngineer,
      this.supplierStartTime,
      this.supplierEndTime,
      this.activityType,
      this.supplierWorkingHours,
      this.assistantEmployees});

  ActivityMaintenance.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    activityStatus = json['activityStatus'] != null ? ActivityStatus.fromJson(json['activityStatus']) : null;
    startTime = json['startTime'];
    endTime = json['endTime'];
    workingHours = json['workingHours'];
    activityType = json['activityType'];
    travelHours = json['travelHours'];
    lastSituation = json['lastSituation'] != null ? Lookup.fromJson(json['lastSituation']) : null;
    repairLocation = json['repairLocation'] != null ? Lookup.fromJson(json['repairLocation']) : null;
    assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null;
    technicalComment = json['technicalComment'];
    //json["supplier"] == null ? null : Lookup.fromJson(json["supplier"]),
    supplier = json["supplier"] == null ? null : Lookup.fromJson(json["supplier"]);
    supplierEngineer = json["supplierEngineer"] == null ? null : Lookup.fromJson(json["supplierEngineer"]);
    // supplierEngineer = json['supplierEngineer'];
    supplierStartTime = json['supplierStartTime'];
    supplierEndTime = json['supplierEndTime'];
    supplierWorkingHours = json['supplierWorkingHours'];
    if (json['assistantEmployees'] != null) {
      assistantEmployees = <AssistantEmployeesModel>[];
      json['assistantEmployees'].forEach((v) {
        assistantEmployees!.add(AssistantEmployeesModel.fromJson(v));
      });
    }
    if (json['activityMaintenanceTimers'] != null) {
      activityMaintenanceTimers = <ActivityMaintenanceTimers>[];
      json['activityMaintenanceTimers'].forEach((v) {
        activityMaintenanceTimers!.add(ActivityMaintenanceTimers.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['activityStatus'] = activityStatus;
    data['startTime'] = startTime;
    data['endTime'] = endTime;
    data['workingHours'] = workingHours;
    data['travelHours'] = travelHours;
    if (repairLocation != null) {
      data['repairLocation'] = repairLocation!.toJson();
    }
    if (assignedEmployee != null) {
      data['assignedEmployee'] = assignedEmployee!.toJson();
    }
    data['technicalComment'] = technicalComment;
    data['supplier'] = supplier;
    data['supplierEngineer'] = supplierEngineer;
    data['supplierStartTime'] = supplierStartTime;
    data['supplierEndTime'] = supplierEndTime;
    data['supplierWorkingHours'] = supplierWorkingHours;
    if (assistantEmployees != null) {
      data['assistantEmployees'] = assistantEmployees!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class RepairLocation {
  int? id;
  String? name;
  int? value;

  RepairLocation({this.id, this.name, this.value});

  RepairLocation.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    value = json['value'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['value'] = value;
    return data;
  }
}

class AssignedEmployee {
  String? userId;
  String? userName;
  String? email;
  int? languageId;

  AssignedEmployee({this.userId, this.userName, this.email, this.languageId});

  AssignedEmployee.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    userName = json['userName'];
    email = json['email'];
    languageId = json['languageId'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['userId'] = userId;
    data['userName'] = userName;
    data['email'] = email;
    data['languageId'] = languageId;
    return data;
  }
}

class ActivityMaintenanceAssistantEmployees {
  DateTime? startDate;
  DateTime? endDate;
  double? workingHours;
  String? technicalComment;
  AssignedEmployee? user;
  AssistantEmployees? employee;

  ActivityMaintenanceAssistantEmployees({this.startDate, this.endDate, this.workingHours, this.technicalComment, this.user, this.employee});

  ActivityMaintenanceAssistantEmployees.fromJson(Map<String, dynamic> json) {
    Map<String, dynamic> assistEmpData = {};

    startDate = json['startDate'] != null ? DateTime.parse(json['startDate']) : null;
    endDate = json['endDate'] != null ? DateTime.parse(json['endDate']) : null;
    workingHours = json['workingHours'];
    technicalComment = json['technicalComment'];
    user = json['user'] != null ? AssignedEmployee.fromJson(json['user']) : null;
    if (json['user'] != null) {
      assistEmpData = {
        'id': null,
        'user': {
          'id': user?.userId,
          'name': user?.userName,
        },
      };
    }
    employee = AssistantEmployees.fromJson(assistEmpData);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['startDate'] = startDate?.toIso8601String();
    data['endDate'] = endDate?.toIso8601String();
    data['workingHours'] = workingHours;
    data['technicalComment'] = technicalComment;
    if (user != null) {
      data['userId'] = user?.userId;
    }
    return data;
  }
}

// class ActivityMaintenanceAssistantEmployees {
//   DateTime? startDate;
//   DateTime? endDate;
//   double? workingHours;
//   String? technicalComment;
//   AssignedEmployee? user;
//
//
//   ActivityMaintenanceAssistantEmployees({this.startDate, this.endDate, this.workingHours, this.technicalComment, this.user});
//
//   ActivityMaintenanceAssistantEmployees.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'];
//     technicalComment = json['technicalComment'];
//     user = json['user'] != null ? AssignedEmployee.fromJson(json['user']) : null;
//   }
//
//   Map<String, dynamic> toJson() {
//     final Map<String, dynamic> data = <String, dynamic>{};
//     data['startDate'] = startDate?.toIso8601String();
//     data['endDate'] = endDate?.toIso8601String();
//     data['workingHours'] = workingHours;
//     data['technicalComment'] = technicalComment;
//     if (user != null) {
//       data['userId'] = user?.userId;
//     }
//     return data;
//   }
// }

class ActivityMaintenanceTimers {
  int? id;
  String? startTime;
  String? endTime;
  dynamic workingHours;

  ActivityMaintenanceTimers({this.id, this.startTime, this.endTime, this.workingHours});

  ActivityMaintenanceTimers.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    startTime = json['startTime'];
    endTime = json['endTime'];
    workingHours = json['workingHours'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['startTime'] = startTime;
    data['endTime'] = endTime;
    data['workingHours'] = workingHours;
    return data;
  }
}

class AssistantEmployeesModel {
  DateTime? startDate;
  DateTime? endDate;
  double? workingHours;
  String? technicalComment;
  AssignedEmployee? user;
  AssistantEmployees? employee;

  AssistantEmployeesModel({this.startDate, this.endDate, this.workingHours, this.technicalComment, this.user, this.employee});

  AssistantEmployeesModel.fromJson(Map<String, dynamic> json) {
    Map<String, dynamic> assistEmpData = {};

    startDate = json['startDate'] != null ? DateTime.parse(json['startDate']) : null;
    endDate = json['endDate'] != null ? DateTime.parse(json['endDate']) : null;
    workingHours = json['workingHours'];
    technicalComment = json['technicalComment'];
    user = json['user'] != null ? AssignedEmployee.fromJson(json['user']) : null;
    if (json['user'] != null) {
      assistEmpData = {
        'id': null,
        'user': {
          'id': user?.userId,
          'name': user?.userName,
        },
      };
    }
    employee = AssistantEmployees.fromJson(assistEmpData);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['startDate'] = startDate?.toIso8601String();
    data['endDate'] = endDate?.toIso8601String();
    data['workingHours'] = workingHours;
    data['technicalComment'] = technicalComment;
    if (user != null) {
      data['userId'] = user?.userId;
    }
    return data;
  }
}
