
class TankersModel {
  String tanker_name = '';
  var capacity='';
  String type_of_water='';
  String phone_number='';
  List capacitiesOfTanker=[];
  List showCapacity=[];
  List waterType=[];
  List showTypeofWater=[];
  var typeOfWaterForBooking=[];
  var capacitiesForBooking=[];

  bool isFiveChecked=false;
  bool isTenChecked=false;
  bool isFifteenChecked=false;
  bool isTwentyChecked=false;
  bool isDrinkingChecked=false;
  bool isBoreChecked=false;
  List updatedCapacities=[];
  List updatedWaterTypes=[];


  TankersModel();


  factory TankersModel.fromJson(Map<String, dynamic> json){
    TankersModel rtvm = new TankersModel();

    rtvm.tanker_name = json['tankerName'] ?? '';
    rtvm.phone_number = json['phoneNumber'] ?? '';
    rtvm.capacitiesOfTanker = json['capacity']??[];

    rtvm.capacitiesOfTanker.forEach((element) {

      rtvm.showCapacity.add(element['capacity']);

      rtvm.capacitiesForBooking.add(element['capacity']);

      rtvm.capacity=rtvm.showCapacity.join(",");

      if(element['capacity']=='5000'){

        rtvm.isFiveChecked=true;
        rtvm.updatedCapacities.add({'capacity': '5000'});
      }
      else if(element['capacity']=='10000'){
        rtvm.isTenChecked=true;
        rtvm.updatedCapacities.add({'capacity': '10000'});
      }
      else if(element['capacity']=='15000'){
        rtvm.isFifteenChecked=true;
        rtvm.updatedCapacities.add({'capacity': '15000'});
      }
      else if(element['capacity']=='20000'){
        rtvm.isTwentyChecked=true;
        rtvm.updatedCapacities.add({'capacity': '20000'});
      }
      else{
        rtvm.isFiveChecked=false;
        rtvm.isFiveChecked=false;
        rtvm.isFiveChecked=false;
        rtvm.isTwentyChecked=false;

        rtvm.updatedCapacities.remove({'capacity': '5000'});
        rtvm.updatedCapacities.remove({'capacity': '10000'});
        rtvm.updatedCapacities.remove({'capacity': '15000'});
        rtvm.updatedCapacities.remove({'capacity': '20000'});
      }

    });

    rtvm.waterType = json['typeofwater']??[];
    rtvm.waterType.forEach((element) {

      rtvm.showTypeofWater.add(element['typeofwater']);

      rtvm.typeOfWaterForBooking.add(element['typeofwater']);

      rtvm.type_of_water=rtvm.showTypeofWater.join(",");

      if(element['typeofwater'].toString().toUpperCase()=='DRINKING WATER'){

        rtvm.isDrinkingChecked=true;
        rtvm.updatedWaterTypes.add({'typeofwater': 'Drinking Water'});
      }
      else if(element['typeofwater'].toString().toUpperCase()=='BORE WATER'){

        rtvm.isBoreChecked=true;
        rtvm.updatedWaterTypes.add({'typeofwater': 'Bore Water'});
      }
      else{
        rtvm.isBoreChecked=false;
        rtvm.isDrinkingChecked=false;
        rtvm.updatedWaterTypes.remove({'typeofwater': 'Drinking Water'});
        rtvm.updatedWaterTypes.remove({'typeofwater': 'Bore Water'});
      }
    });

    return rtvm;
  }
  Map<String, dynamic> toJson() => {
    "tankerName":this.tanker_name,
    "capacity": this.capacity,
    "typeofwater": this.type_of_water ,
    "phoneNumber": this.phone_number,
    "capacity": this.capacitiesOfTanker,
    "typeofwater": this.waterType,
  };
}