import '../lookup.dart';
import 'visit.dart';

class VisitsGroup {
  String? userId;
  String? workingHours;
  String? travelingHours;
  String? jobSheetNumber;
  String? image;
  Lookup? status;
  Lookup? taskStatus;
  DateTime? date;
  List<Visit>? visits;

  VisitsGroup({
    this.userId,
    this.status,
    this.date,
    this.jobSheetNumber,
    this.travelingHours,
    this.workingHours,
    this.visits,
    this.image,
    this.taskStatus,
  });

  Map<String, String> toJson() {
    Map<String, String> jsonObject = {};
    jsonObject["nids"] = visits!.map((e) => e.id).toList().join(',');
    if (status != null) jsonObject["status"] = status?.id.toString() ?? "";
    if (date != null) jsonObject["date"] = date.toString().split(" ").first;
    if (jobSheetNumber != null && (jobSheetNumber?.isNotEmpty ?? false)) {
      jsonObject["job_sheet_no"] = jobSheetNumber!;
    }
    if (travelingHours != null && (travelingHours?.isNotEmpty ?? false)) {
      jsonObject["traveling_hours"] = travelingHours ?? "";
    }
    if (workingHours != null && (workingHours?.isNotEmpty ?? false)) {
      jsonObject["working_hours"] = workingHours ?? "";
    }
    if (image != null) jsonObject["image"] = image ?? "";
    if (taskStatus != null) jsonObject["task_status"] = taskStatus?.id.toString() ?? "";
    return jsonObject;
  }
}
