import '../lookup.dart';

class Visit {
  String? id;
  String? serialNumber;
  String? expectDate;
  String? actualDate;
  String? hospitalId;
  String? hospitalName;
  String? deviceId;
  String? deviceSerialNumber;
  String? deviceArabicName;
  String? deviceEnglishName;
  String? employId;
  String? employName;
  String? modelAndBrand;
  String? contactStatus;
  Lookup? status;
  String? assignTo;
  String? deviceNumber;
  List<String>? images;

  Visit({
    this.id,
    this.serialNumber,
    this.hospitalId,
    this.hospitalName,
    this.deviceId,
    this.deviceSerialNumber,
    this.deviceArabicName,
    this.deviceEnglishName,
    this.employId,
    this.employName,
    this.expectDate,
    this.actualDate,
    this.status,
    this.modelAndBrand,
    this.contactStatus,
    this.images,
    this.assignTo,
    this.deviceNumber,
  });

  factory Visit.fromJson(Map<String, dynamic> parsedJson) {
    return Visit(
      id: parsedJson["nid"],
      serialNumber: parsedJson["title"],
      hospitalId: parsedJson["client"],
      deviceNumber: parsedJson["device_no"],
      hospitalName: parsedJson["client_name"],
      deviceId: parsedJson["medical_equipment_nid"],
      deviceSerialNumber: parsedJson["medical_equipment"],
      deviceEnglishName: parsedJson["equipment_english_name"],
      deviceArabicName: parsedJson["equipment_arabic_name"],
      employId: parsedJson["assigned_employee"],
      employName: parsedJson["assigned_employee_name"],
      expectDate: parsedJson["expected_date"],
      actualDate: parsedJson["actual_date"],
      modelAndBrand: parsedJson["mode_brand"],
      contactStatus: parsedJson["contactStatus"],
      images: List<String>.from(parsedJson["images"] ?? []),
      status: Lookup(
          id: int.tryParse(parsedJson["status"] ?? "-1") ?? -1, // actual value (0,1,2)
          label: parsedJson["status_value"] // text value
          ),
      assignTo: parsedJson["assigned_to"],
    );
  }
}
