import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/new_models/building.dart';
import 'package:test_sa/models/new_models/floor.dart';
import 'package:test_sa/models/new_models/room_model.dart';
import 'package:test_sa/models/new_models/site.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/demo_module/models/demo_attachment_model.dart';
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';

import '../../../models/new_models/department.dart';

class DemoFormModel {
  String? docName;
  int? id;
  String? docNumber;
  String? docEmail;
  String? itemDescription;
  String? requestDescription;
  String? model;
  String? assetName;
  String? manufacturer;
  Lookup? demoPeriod;
  String? vendorRepresentativeName;
  String? vendorName;
  String? vendorContactNumber;
  String? vendorEmail;
  Site? site;
  Building? building; // Now nullable
  Floor? floor; // Now nullable
  Department? department; // Now nullable
  Rooms? room;
  SuppEngineerWorkOrders? supEngineer;
  SupplierDetails? vendor;
  List<GenericAttachmentModel>? demoAttachment;

  bool demoEaluationAcknowledge;
  bool acknowledgeNotEquipment;

  DemoFormModel({
    this.id,
    this.docName,
    this.docNumber,
    this.docEmail,
    this.itemDescription,
    this.requestDescription,
    this.model,
    this.assetName,
    this.manufacturer,
    this.demoPeriod,
    this.vendorRepresentativeName,
    this.vendorName,
    this.vendorContactNumber,
    this.vendorEmail,
    this.demoAttachment,
    this.site,
    this.vendor,
    this.supEngineer,
    this.department,
    this.demoEaluationAcknowledge = false,
    this.acknowledgeNotEquipment = false,
  });

  Map<String, dynamic> toJson() {
    return {
      "id": id ?? 0,
      'siteId': site?.id,
      'departmentId': department?.id,
      "buildingId": building?.id,
      "floorId": floor?.id,
      "assetName": assetName,
      "isSubmit": true,
      "doctorName": docName,
      "doctorContactNumber": docNumber,
      "doctorContactEmail": docEmail,
      "itemDescription": itemDescription,
      "requestDescription": requestDescription,
      "model": model,
      "vendorName": vendorName,
      "vendorContactNumber": vendorContactNumber,
      "vendorEmail": vendorEmail,
      "vendorRepresentativeName": vendorRepresentativeName,
      "manufacturer": manufacturer,
      "demoPeriodId": demoPeriod?.id,
      "supplierId": vendor?.id,
      "suppPersonId": supEngineer?.id,
      "demoEaluationAcknowledge": demoEaluationAcknowledge,
      "acknowledgeNotEquipment": acknowledgeNotEquipment,
      "demoAttachments":
          demoAttachment != null ? demoAttachment!.map((v) => v.toDemoJson()).toList() : [],
    };
  }

  Map<String, dynamic> toUpdateJson() {
    return {
      "id": id,
      "supplierId": vendor?.id,
      "suppPersonId": supEngineer?.id,
      "demoAttachments": demoAttachment != null ? demoAttachment!.whereType<GenericAttachmentModel>().map((v) => v.toDemoJson()).toList() : [],
    };
  }
}
