import 'package:test_sa/models/hospital.dart';
import 'package:test_sa/models/lookup.dart';

class ServiceRequestSearch{
  String deviceSerialNumber;
  String deviceNumber;
  String deviceName;
  Hospital hospital;
  String model;
  Lookup statusValue;


  ServiceRequestSearch({
    this.deviceSerialNumber,
    this.deviceNumber,
    this.statusValue,
    this.deviceName,
    this.model,
    this.hospital,
  });

  fromSearch(ServiceRequestSearch newSearch){
    deviceSerialNumber = newSearch.deviceSerialNumber;
    deviceNumber = newSearch.deviceNumber;
    statusValue = newSearch.statusValue;
    hospital = newSearch.hospital;
    model = newSearch.model;
  }

  Map<String,dynamic> toMap(){
    Map<String,dynamic> search = {};
    if(deviceSerialNumber != null  && deviceSerialNumber.isNotEmpty){
      search["assetSerialNumber"] = deviceSerialNumber;
    }

    if(deviceNumber != null  && deviceNumber.isNotEmpty){
      search["assetNo"] = deviceNumber;
    }

    if(statusValue != null){
      search["status"] = statusValue.toMap();
    }

    if(deviceName != null && deviceName.isNotEmpty){
      search["assetName"] = deviceName;

    }

    if(hospital != null){
      search["site"] = hospital.name;
    }

    if(model != null){
      search["modelDefinition"] = model;
    }
    return search;
  }
}