import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';

class WaterLeakStatusModel {
  final String productUuid;
  final String productType;
  final String watersensorState;
  final int batteryPercentage;

  WaterLeakStatusModel({
    required this.productUuid,
    required this.productType,
    required this.watersensorState,
    required this.batteryPercentage,
  });
  factory WaterLeakStatusModel.fromJson(String id, List<Status> jsonList) {
    late String watersensorState;
    late int batteryPercentage;

    for (var i = 0; i < jsonList.length; i++) {
      if (jsonList[i].code == 'watersensor_state') {
        watersensorState = jsonList[i].value;
      } else if (jsonList[i].code == 'battery_percentage') {
        batteryPercentage = jsonList[i].value;
      }
    }

    return WaterLeakStatusModel(
      productUuid: id,
      productType: 'WL',
      watersensorState: watersensorState,
      batteryPercentage: batteryPercentage,
    );
  }

  WaterLeakStatusModel copyWith({
    String? productUuid,
    String? productType,
    String? watersensorState,
    int? batteryPercentage,
  }) {
    return WaterLeakStatusModel(
      productUuid: productUuid ?? this.productUuid,
      productType: productType ?? this.productType,
      watersensorState: watersensorState ?? this.watersensorState,
      batteryPercentage: batteryPercentage ?? this.batteryPercentage,
    );
  }
}
