import '../lookup.dart';

class GasRefillDetails {
  Lookup? type;
  Lookup? cylinderSize;
  int? requestedQuantity;
  int? deliveredQuantity;

  GasRefillDetails({
    this.type,
    this.cylinderSize,
    this.requestedQuantity,
    this.deliveredQuantity,
    required model,
  });

  bool validate() {
    //if(cylinderSize == null) return false;
    if (type == null) return false;
    if (requestedQuantity == null) return false;
    return true;
  }

  factory GasRefillDetails.fromJson(Map<String, dynamic> parsedJson) {
    return GasRefillDetails(
      type: Lookup.fromJson(parsedJson["type"]),
      cylinderSize: Lookup.fromJson(parsedJson["size"]),
      requestedQuantity: parsedJson["requsted_qty"] == null ? 0 : int.tryParse(parsedJson["requsted_qty"].toString()) ?? 0,
      deliveredQuantity: parsedJson["deliverd_qty"] == null ? 0 : int.tryParse(parsedJson["deliverd_qty"].toString()) ?? 0,
      model: null,
    );
  }

  factory GasRefillDetails.fromDetails(GasRefillDetails details) {
    return GasRefillDetails(
      type: details.type != null ? Lookup.fromStatus(details.type!) : null,
      cylinderSize: details.cylinderSize != null ? Lookup.fromStatus(details.cylinderSize!) : null,
      requestedQuantity: details.requestedQuantity,
      deliveredQuantity: details.deliveredQuantity,
      model: null,
    );
  }
}
