import 'package:test_sa/models/device/asset_by_id_model.dart';
import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart';
import 'package:test_sa/models/service_request/supplier_details.dart';
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';

class DemoRequestModel {
  int? id;
  RequesterUserModel? requesterUser;
  Site? site;
  Lookup? building;
  Lookup? floor;
  MedicalDepartmentModel? department;
  String? assetName;
  String? model;
  String? manufacturer;
  String? doctorName;
  String? doctorContactNumber;
  String? doctorContactEmail;
  String? itemDescription;
  String? requestDescription;
  String? vendorName;
  String? vendorRepresentativeName;
  String? vendorContactNumber;
  String? vendorEmail;
  Lookup? demoPeriod;
  SupplierDetails? supplier;
  SuppEngineerWorkOrders? suppPerson;
  Lookup? status;
  Lookup? endUserStatus;
  List<GenericAttachmentModel>? demoAttachments;
  List<GenericAttachmentModel>? supplierDemoAttachments;
  dynamic demoAsset;
  dynamic demoInstallationTaskJob;
  dynamic demoPullOutTaskJob;
  bool? isDemoPeriodExpired;
  String? requestNo;
  String? demoNo;

  DemoRequestModel({
    this.id,
    this.requesterUser,
    this.site,
    this.building,
    this.floor,
    this.department,
    this.assetName,
    this.model,
    this.manufacturer,
    this.doctorName,
    this.doctorContactNumber,
    this.doctorContactEmail,
    this.itemDescription,
    this.requestDescription,
    this.vendorName,
    this.vendorRepresentativeName,
    this.vendorEmail,
    this.vendorContactNumber,
    this.demoPeriod,
    this.supplier,
    this.suppPerson,
    this.status,
    this.endUserStatus,
    this.demoAttachments,
    this.supplierDemoAttachments,
    this.demoAsset,
    this.demoInstallationTaskJob,
    this.demoPullOutTaskJob,
    this.isDemoPeriodExpired,
    this.requestNo,
    this.demoNo,
  });

  DemoRequestModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    requesterUser = json['requesterUser'] != null ? (RequesterUserModel()..fromJson(json['requesterUser'])) : null;
    site = json['site'] != null ? (Site.fromJson(json['site'])) : null;
    building = json['building'] != null ? (Lookup.fromJson(json['building'])) : null;
    floor = json['floor'] != null ? (Lookup.fromJson(json['floor'])) : null;
    department = json['department'] != null ? (MedicalDepartmentModel.fromJson(json['department'])) : null;
    assetName = json['assetName'];
    model = json['model'];
    manufacturer = json['manufacturer'];
    doctorName = json['doctorName'];
    doctorContactNumber = json['doctorContactNumber'];
    doctorContactEmail = json['doctorContactEmail'];
    itemDescription = json['itemDescription'];
    requestDescription = json['requestDescription'];
    vendorName = json['vendorName'];
    vendorRepresentativeName = json['vendorRepresentativeName'];
    vendorContactNumber = json['vendorContactNumber'];
    vendorEmail = json['vendorEmail'];
    demoPeriod = json['demoPeriod'] != null ? (Lookup.fromJson(json['demoPeriod'])) : null;
    supplier = json['supplier'] != null ? (SupplierDetails.fromJson(json['supplier'])) : null;
    suppPerson = json['suppPerson'] != null ? (SuppEngineerWorkOrders.fromJson(json['suppPerson'])) : null;
    status = json['status'] != null ? (Lookup.fromJson(json['status'])) : null;
    endUserStatus = json['endUserStatus'] != null ? (Lookup.fromJson(json['endUserStatus'])) : null;
    demoAttachments = json['demoAttachments'] != null ? (json['demoAttachments'] as List).map((e) => GenericAttachmentModel.fromDemoJson(e)).toList() : null;
    supplierDemoAttachments = json['supplierDemoAttachments'] != null ? (json['supplierDemoAttachments'] as List).map((e) => GenericAttachmentModel.fromDemoJson(e)).toList() : null;
    demoAsset = json['demoAsset'];
    demoInstallationTaskJob = json['demoInstallationTaskJob'];
    demoPullOutTaskJob = json['demoPullOutTaskJob'];
    isDemoPeriodExpired = json['isDemoPeriodExpired'];
    requestNo = json['requestNo'];
    demoNo = json['demoNo'];
  }

  Map<String, dynamic> toJson() {
    return {
      "id": 0,
      'siteId': site?.id,
      'departmentId': department?.id,
      "buildingId": 0,
      "floorId": 0,
      "assetName": assetName,
      "isSubmit": true,
      "itemDescription": itemDescription,
      "requestDescription": requestDescription,
      "model": model,
      "requestNo": requestNo,
      "demoNo": demoNo,
      "manufacturer": manufacturer,
      "demoPeriodId": demoPeriod?.id,
      "supplierId": supplier?.id,
      "suppPersonId": suppPerson?.id,
      "demoAttachments": demoAttachments != null ? demoAttachments!.whereType<GenericAttachmentModel>().map((v) => v.toDemoJson()).toList() : [],
      "supplierDemoAttachments": supplierDemoAttachments != null ? supplierDemoAttachments!.whereType<GenericAttachmentModel>().map((v) => v.toDemoJson()).toList() : [],
    };
  }
}

class RequesterUserModel {
  String? requesterUserId;
  String? requesterName;
  String? requesterEmail;
  String? requesterMobile;

  RequesterUserModel();

  void fromJson(Map<String, dynamic> json) {
    requesterUserId = json['requesterUserId'];
    requesterName = json['requesterName'];
    requesterEmail = json['requesterEmail'];
    requesterMobile = json['requesterMobile'];
  }

  Map<String, dynamic> toJson() => {
        'requesterUserId': requesterUserId,
        'requesterName': requesterName,
        'requesterEmail': requesterEmail,
        'requesterMobile': requesterMobile,
      };
}
