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

class MainDoorSensorStatusModel {
  final String uuid;
  final bool doorContactState;
  final int batteryPercentage;

  MainDoorSensorStatusModel({
    required this.uuid,
    required this.doorContactState,
    required this.batteryPercentage,
  });

  factory MainDoorSensorStatusModel.fromJson(String id, List<Status> jsonList) {
    late bool doorContactState = false;
    late int batteryPercentage = 0;

    for (var status in jsonList) {
      switch (status.code) {
        case 'doorcontact_state':
          doorContactState = status.value ?? false;
          break;
        case 'battery_percentage':
          batteryPercentage = status.value ?? 0;
          break;
      }
    }

    return MainDoorSensorStatusModel(
      uuid: id,
      doorContactState: doorContactState,
      batteryPercentage: batteryPercentage,
    );
  }

  MainDoorSensorStatusModel copyWith({
    String? uuid,
    bool? doorContactState,
    int? batteryPercentage,
  }) {
    return MainDoorSensorStatusModel(
      uuid: uuid ?? this.uuid,
      doorContactState: doorContactState ?? this.doorContactState,
      batteryPercentage: batteryPercentage ?? this.batteryPercentage,
    );
  }
}
