import '../lookup.dart';

class DeviceTransferSearch {
  String assetName, assetNumber, site;
  bool mostRecent;
  Lookup dateOperator;
  String from, to;

  DeviceTransferSearch({
    this.assetName,
    this.assetNumber,
    this.site,
    this.mostRecent,
    this.dateOperator,
    this.from,
    this.to,
  });

  Map<String, dynamic> toMap() {
    Map<String, dynamic> search = {};
    if (assetName != null && assetName.isNotEmpty) {
      search["assetName"] = assetName;
    }
    if (assetNumber != null && assetNumber.isNotEmpty) {
      search["assetNumber"] = assetNumber;
    }
    if (site != null && site.isNotEmpty) {
      search["site"] = site;
    }
    if (dateOperator != null && from != null) {
      search["requestedDateSymbol"] = dateOperator.toMap();
      search["requestedDateFrom"] = from;
    }
    if (dateOperator != null && to != null) {
      search["requestedDateTo"] = to;
    }
    return search;
  }

  void fromSearch(DeviceTransferSearch newSearch) {
    assetName = newSearch.assetName;
    assetNumber = newSearch.assetNumber;
    site = newSearch.site;
    mostRecent = newSearch.mostRecent;
    from = newSearch.from;
    to = newSearch.to;
    dateOperator = newSearch.dateOperator;
  }
}
