import 'package:syncrow_app/features/devices/model/status_model.dart';

class DoorSensorModel {
  bool doorContactState;
  int batteryPercentage;

  DoorSensorModel({
    required this.doorContactState,
    required this.batteryPercentage,
  });

  factory DoorSensorModel.fromJson(List<StatusModel> jsonList) {
    bool _doorContactState = false;
    int _batteryPercentage = 0;

    for (int i = 0; i < jsonList.length; i++) {
      if (jsonList[i].code == 'doorcontact_state') {
        _doorContactState = jsonList[i].value ?? false;
      } else if (jsonList[i].code == 'battery_percentage') {
        _batteryPercentage = jsonList[i].value ?? 0;
      }
    }
    return DoorSensorModel(
      doorContactState: _doorContactState,
      batteryPercentage: _batteryPercentage,
    );
  }
}
