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

class DeviceSearch {

  DeviceSearch(
      {this.code,
      this.assetSerialNumber,
      this.assetName,
      this.supplyDateSymbol,
      this.supplyDateFrom,
      this.supplyDateTo,
      this.warrantyEndDateSymbol,
      this.warrantyEndDateFrom,
      this.warrantyEndDateTo,
      this.delieveryInspectionDateSymbol,
      this.deliveryInspectionDateFrom,
      this.deliveryInspectionDateTo,
      this.maintenanceContract,
      this.assetClassification,
      this.assetStatus,
      this.assetNotScraped,
      this.assetNo,
      this.modelDefinition,
      this.site,
      this.manufacturer,
      this.model,
      this.department,
      this.supplier,
      this.tagCode,
      this.assetGroupName,
      this.assetGroup,
      this.oracleCodeTypeId,
      this.oracleCodeValue});

  DeviceSearch.fromJson(dynamic json) {
    code = json['code'];
    assetSerialNumber = json['assetSerialNumber'];
    assetName = json['assetName'];
    supplyDateSymbol = json['supplyDateSymbol'] != null ? Lookup.fromJson(json['supplyDateSymbol']) : null;
    supplyDateFrom = json['supplyDateFrom'];
    supplyDateTo = json['supplyDateTo'];
    warrantyEndDateSymbol = json['warrantyEndDateSymbol'];
    warrantyEndDateFrom = json['warrantyEndDateFrom'];
    warrantyEndDateTo = json['warrantyEndDateTo'];
    delieveryInspectionDateSymbol = json['delieveryInspectionDateSymbol'];
    deliveryInspectionDateFrom = json['deliveryInspectionDateFrom'];
    deliveryInspectionDateTo = json['deliveryInspectionDateTo'];
    maintenanceContract = json['maintenanceContract'] != null ? Lookup.fromJson(json['maintenanceContract']) : null;
    assetClassification = json['assetClassification'] != null ? Lookup.fromJson(json['assetClassification']) : null;
    assetStatus = json['assetStatus'] != null ? Lookup.fromJson(json['assetStatus']) : null;
    assetNotScraped = json['assetNotScraped'] != null ? Lookup.fromJson(json['assetNotScraped']) : null;
    assetNo = json['assetNo'];
    modelDefinition = json['modelDefinition'];
    site = json['site'];
    manufacturer = json['manufacturer'];
    model = json['model'];
    department = json['department'];
    supplier = json['supplier'];
    tagCode = json['tagCode'];
    assetGroupName = json['assetGroupName'];
    assetGroup = json['assetGroup'] != null ? Lookup.fromJson(json['assetGroup']) : null;
    oracleCodeTypeId = json['assetOracleCodeTypeId'];
    oracleCodeValue = json['assetOracleCodeValue'];
  }

  String? code; // Now nullable
  String? assetSerialNumber; // Now nullable
  String? assetName; // Now nullable
  Lookup? supplyDateSymbol; // Now nullable
  String? supplyDateFrom; // Now nullable
  String? supplyDateTo; // Now nullable
  num? warrantyEndDateSymbol; // Now nullable
  String? warrantyEndDateFrom; // Now nullable
  String? warrantyEndDateTo; // Now nullable
  num? delieveryInspectionDateSymbol; // Now nullable
  String? deliveryInspectionDateFrom; // Now nullable
  String? deliveryInspectionDateTo; // Now nullable
  Lookup? maintenanceContract; // Now nullable
  Lookup? assetClassification; // Now nullable
  Lookup? assetStatus; // Now nullable
  Lookup? assetNotScraped; // Now nullable
  String? assetNo; // Now nullable
  String? modelDefinition; // Now nullable
  List<String>? sites; // Changed to List for multiple selection
  String? site; // Keep for backward compatibility
  String? manufacturer; // Now nullable
  String? model; // Now nullable
  List<String>? departments; // Changed to List for multiple selection
  String? department; // Keep for backward compatibility
  String? supplier; // Now nullable
  String? tagCode; // Now nullable
  String? assetGroupName; // Now nullable
  Lookup? assetGroup; // Now nullable
  String? oracleCodeValue; // Now nullable
  int? oracleCodeTypeId;

  DeviceSearch copyWith(
          {String? code,
          String? assetSerialNumber,
          String? assetName,
          Lookup? supplyDateSymbol,
          String? supplyDateFrom,
          String? supplyDateTo,
          num? warrantyEndDateSymbol,
          String? warrantyEndDateFrom,
          String? warrantyEndDateTo,
          num? delieveryInspectionDateSymbol,
          String? deliveryInspectionDateFrom,
          String? deliveryInspectionDateTo,
          Lookup? maintenanceContract,
          Lookup? assetClassification,
          Lookup? assetStatus,
          Lookup? assetNotScraped,
          String? assetNo,
          String? modelDefinition,
          String? site,
          String? manufacturer,
          String? model,
          String? department,
          String? supplier,
          String? tagCode,
          String? assetGroupName,
          Lookup? assetGroup,
          String? oracleCodeValue,
          int? oracleCodeTypeId}) =>
      DeviceSearch(
          code: code ?? this.code,
          assetSerialNumber: assetSerialNumber ?? this.assetSerialNumber,
          assetName: assetName ?? this.assetName,
          supplyDateSymbol: supplyDateSymbol ?? this.supplyDateSymbol,
          supplyDateFrom: supplyDateFrom ?? this.supplyDateFrom,
          supplyDateTo: supplyDateTo ?? this.supplyDateTo,
          warrantyEndDateSymbol: warrantyEndDateSymbol ?? this.warrantyEndDateSymbol,
          warrantyEndDateFrom: warrantyEndDateFrom ?? this.warrantyEndDateFrom,
          warrantyEndDateTo: warrantyEndDateTo ?? this.warrantyEndDateTo,
          delieveryInspectionDateSymbol: delieveryInspectionDateSymbol ?? this.delieveryInspectionDateSymbol,
          deliveryInspectionDateFrom: deliveryInspectionDateFrom ?? this.deliveryInspectionDateFrom,
          deliveryInspectionDateTo: deliveryInspectionDateTo ?? this.deliveryInspectionDateTo,
          maintenanceContract: maintenanceContract ?? this.maintenanceContract,
          assetClassification: assetClassification ?? this.assetClassification,
          assetStatus: assetStatus ?? this.assetStatus,
          assetNotScraped: assetNotScraped ?? this.assetNotScraped,
          assetNo: assetNo ?? this.assetNo,
          modelDefinition: modelDefinition ?? this.modelDefinition,
          site: site ?? this.site,
          manufacturer: manufacturer ?? this.manufacturer,
          model: model ?? this.model,
          department: department ?? this.department,
          supplier: supplier ?? this.supplier,
          tagCode: tagCode ?? this.tagCode,
          assetGroupName: assetGroupName ?? this.assetGroupName,
          assetGroup: assetGroup ?? this.assetGroup,
          oracleCodeValue: oracleCodeValue ?? this.oracleCodeValue,
          oracleCodeTypeId: oracleCodeTypeId ?? this.oracleCodeTypeId);

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    if (code != null && code!.isNotEmpty) map['code'] = code;
    if (assetSerialNumber != null && assetSerialNumber!.isNotEmpty) map['assetSerialNumber'] = assetSerialNumber;
    if (assetName != null && assetName!.isNotEmpty) map['assetName'] = assetName; // todo @discuss baha about multiple asset search
    if (supplyDateSymbol != null) {
      map['supplyDateSymbol'] = supplyDateSymbol!.toJson();
    }
    if (supplyDateFrom != null && supplyDateFrom!.isNotEmpty) map['supplyDateFrom'] = supplyDateFrom;
    if (supplyDateTo != null && supplyDateTo!.isNotEmpty) map['supplyDateTo'] = supplyDateTo;
    if (warrantyEndDateSymbol != null) map['warrantyEndDateSymbol'] = warrantyEndDateSymbol;
    if (warrantyEndDateFrom != null && warrantyEndDateFrom!.isNotEmpty) map['warrantyEndDateFrom'] = warrantyEndDateFrom;
    if (warrantyEndDateTo != null && warrantyEndDateTo!.isNotEmpty) map['warrantyEndDateTo'] = warrantyEndDateTo;
    if (delieveryInspectionDateSymbol != null) map['delieveryInspectionDateSymbol'] = delieveryInspectionDateSymbol;
    if (deliveryInspectionDateFrom != null && deliveryInspectionDateFrom!.isNotEmpty) map['deliveryInspectionDateFrom'] = deliveryInspectionDateFrom;
    if (deliveryInspectionDateTo != null && deliveryInspectionDateTo!.isNotEmpty) map['deliveryInspectionDateTo'] = deliveryInspectionDateTo;
    if (maintenanceContract != null) {
      map['maintenanceContract'] = maintenanceContract!.toJson();
    }
    if (assetClassification != null) {
      map['assetClassification'] = assetClassification!.toJson();
    }
    if (assetStatus != null) {
      map['assetStatus'] = assetStatus!.toJson();
    }
    if (assetNotScraped != null) {
      map['assetNotScraped'] = assetNotScraped!.toJson();
    }
    if (assetNo != null && assetNo!.isNotEmpty) map['assetNo'] = assetNo;
    if (modelDefinition != null && modelDefinition!.isNotEmpty) map['modelDefinition'] = modelDefinition;
    if (sites != null && sites!.isNotEmpty) {
      map['site'] = sites;
    } else if (site != null && site!.isNotEmpty) {
      map['site'] = site;
    }
    if (manufacturer != null && manufacturer!.isNotEmpty) map['manufacturer'] = manufacturer;
    if (model != null && model!.isNotEmpty) map['model'] = model;
    if (departments != null && departments!.isNotEmpty) {
      map['department'] = departments;
    } else if (department != null && department!.isNotEmpty) {
      map['department'] = department;
    }
    if (supplier != null && supplier!.isNotEmpty) map['supplier'] = supplier;
    if (tagCode != null && tagCode!.isNotEmpty) map['tagCode'] = tagCode;
    if (assetGroupName != null && assetGroupName!.isNotEmpty) map['assetGroupName'] = assetGroupName;
    if (assetGroup != null) {
      map['assetGroup'] = assetGroup!.toJson();
    }
    if (oracleCodeValue != null && oracleCodeValue!.isNotEmpty) map['assetOracleCodeValue'] = oracleCodeValue;
    if (oracleCodeTypeId != null) map['assetOracleCodeTypeId'] = oracleCodeTypeId;
    return map;
  }
}
