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

class WallSensorModel {
  String presenceState;
  int farDetection;
  int presenceTime;
  int motionSensitivity;
  int motionlessSensitivity;
  int currentDistance;
  int illuminance;
  bool indicator;
  int noBodyTime;

  WallSensorModel(
      {required this.presenceState,
      required this.farDetection,
      required this.presenceTime,
      required this.motionSensitivity,
      required this.motionlessSensitivity,
      required this.currentDistance,
      required this.illuminance,
      required this.indicator,
      required this.noBodyTime});

  factory WallSensorModel.fromJson(List<Status> jsonList) {
    late String _presenceState;
    late int _farDetection;
    late int _presenceTime;
    late int _motionSensitivity;
    late int _motionlessSensitivity;
    late int _currentDistance;
    late int _illuminance;
    late bool _indicator;
    late int _noBodyTime;

    for (int i = 0; i < jsonList.length; i++) {
      if (jsonList[i].code == 'presence_state') {
        _presenceState = jsonList[i].value ?? 'none';
      } else if (jsonList[i].code == 'far_detection') {
        _farDetection = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'presence_time') {
        _presenceTime = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'motion_sensitivity_value') {
        _motionSensitivity = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'motionless_sensitivity') {
        _motionlessSensitivity = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'dis_current') {
        _currentDistance = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'illuminance_value') {
        _illuminance = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'indicator') {
        _indicator = jsonList[i].value ?? false;
      } else if (jsonList[i].code == 'no_one_time') {
        _noBodyTime = jsonList[i].value ?? 0;
      }
    }
    return WallSensorModel(
        presenceState: _presenceState,
        farDetection: _farDetection,
        presenceTime: _presenceTime,
        motionSensitivity: _motionSensitivity,
        motionlessSensitivity: _motionlessSensitivity,
        currentDistance: _currentDistance,
        illuminance: _illuminance,
        indicator: _indicator,
        noBodyTime: _noBodyTime);
  }
}
