import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/pantry/pentry.dart';

class Visit {
  int id;
  String serialNumber;
  String expectDate;
  String actualDate;
  String createdOn;
  int hospitalId;
  String hospitalName;
  int deviceId;
  int ppmScheduleId;
  String deviceSerialNumber;
  String deviceArabicName;
  String deviceEnglishName;
  String employId;
  String employName;
  String modelAndBrand;
  Pentry pentry;
  Lookup status;
  String assignTo;
  String deviceNumber;
  List<String> images;

  Visit({
    this.id,
    this.ppmScheduleId,
    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.pentry,
    this.images,
    this.assignTo,
    this.deviceNumber,
    this.createdOn,
  });

  factory Visit.fromJson(Map<String, dynamic> parsedJson) {
    List<String> images = [];
    if (parsedJson["vAttachments"] is List) {
      List list = parsedJson["vAttachments"];
      images = list.map((e) => e["attachmentURL"].toString()).toList();
    }
    return Visit(
      id: parsedJson["id"],
      serialNumber: parsedJson["visitCode"],
      ppmScheduleId: parsedJson["ppmScheduleId"],
      hospitalId: parsedJson["siteId"],
      deviceNumber: parsedJson["assetNumber"],
      hospitalName: parsedJson["siteName"],
      deviceId: parsedJson["assetId"],
      deviceSerialNumber: parsedJson["assetSerialNo"],
      deviceEnglishName: parsedJson["assetName"],
      deviceArabicName: parsedJson["assetName"],
      employId: parsedJson["assignedEmployeeId"].toString(),
      employName: parsedJson["assignedEmployeeName"],
      expectDate: parsedJson["expectedDate"].toString().split("T").first,
      actualDate: parsedJson["actualDate"].toString().split("T").first,
      modelAndBrand: "${parsedJson["modelName"]} / ${parsedJson["manufacturerName"]}",
      // contactStatus: parsedJson["contactStatus"],
      images: images,
      status: Lookup(
          id: parsedJson["visitStatusId"], // actual value (0,1,2)
          name: parsedJson["visitStatusName"] // text value
          ),
      assignTo: parsedJson["assignedToName"],
      pentry: Pentry.fromMap(parsedJson),
      createdOn: parsedJson['createdOn'],
    );
  }
}
