class CargoType {
  String id;
  String name;
  double rate;
  double weight;

  double get calAmount => (calRate ?? 0) * (calWeight ?? 0);

  double calRate;
  double calWeight;

  factory CargoType.fromMap(Map<String, dynamic> map, String id) {
    return CargoType(
      id: id,
      name: map['name'],
      rate: map['rate']?.toDouble() ?? 0,
      weight: map['weight']?.toDouble() ?? 0,
      calWeight: map['cal_weight']?.toDouble() ?? 0,
      calRate: map['cal_rate']?.toDouble() ?? 0,
    );
  }
  CargoType(
      {this.id,
      this.name,
      this.rate,
      this.weight,
      this.calWeight,
      this.calRate});

  Map<String, dynamic> toMap() {
    return {
      "id": id,
      'name': name,
      'rate': rate,
      'weight': weight,
      'cal_weight': calWeight,
      'cal_rate': calRate,
    };
  }

  CargoType clone() {
    return CargoType.fromMap(toMap(), this.id);
  }

  @override
  bool operator ==(Object other) => other is CargoType && other.id == id;

  @override
  int get hashCode => id.hashCode;

  @override
  String toString() {
    return name;
  }
}
