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

class PMKit{
  int id;
  Lookup itemCode;
  String itemName;
  String preparationTimeFrame;
  String kitFrequencyDemand;
  String availability;
  String quantityNeeded;
  String quantityReserved;

  PMKit({
    this.id,
    this.itemCode,
    this.itemName,
    this.preparationTimeFrame,
    this.kitFrequencyDemand,
    this.availability,
    this.quantityNeeded,
    this.quantityReserved
  });

  Map<String, dynamic> toMap(int visitId) {
    return {
      "id":id ?? 0,
      "visitId": visitId,
      if(itemCode != null) 'partCatalogItemId': (itemCode?.id).toString(),
      // if(itemName != null) 'itemName': itemName,
      // if(preparationTimeFrame != null) 'preparationTimeFrame': preparationTimeFrame,
      // if(kitFrequencyDemand != null) 'kitFrequencyDemand': kitFrequencyDemand,
      // if(availability != null) 'availability': availability,
      // if(quantityNeeded != null) 'quantityNeeded': quantityNeeded,
      // if(quantityReserved != null) 'quantityReserved': quantityReserved,
    };
  }

  factory PMKit.fromMap(Map<String, dynamic> map) {
    return PMKit(
      id: map['id'],
      itemCode: Lookup(id:map['partCatalogItemId'],name:map["partNumber"]),
      itemName: map['itemName'] as String,
      preparationTimeFrame: map['preparationTimeFrame'] as String,
      kitFrequencyDemand: map['kitFrequencyDemand'] as String,
      availability: map['availability'] as String,
      quantityNeeded: map['quantityNeeded'] as String,
      quantityReserved: map['quantityReserved'] as String,
    );
  }

  PMKit copyWith({
    int id,
    Lookup itemCode,
    String itemName,
    String preparationTimeFrame,
    String kitFrequencyDemand,
    String availability,
    String quantityNeeded,
    String quantityReserved,
  }) {
    return PMKit(
      id: id ?? this.id,
      itemCode: itemCode ?? this.itemCode,
      itemName: itemName ?? this.itemName,
      preparationTimeFrame: preparationTimeFrame ?? this.preparationTimeFrame,
      kitFrequencyDemand: kitFrequencyDemand ?? this.kitFrequencyDemand,
      availability: availability ?? this.availability,
      quantityNeeded: quantityNeeded ?? this.quantityNeeded,
      quantityReserved: quantityReserved ?? this.quantityReserved,
    );
  }
}