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

class GarageDoorModel {
  bool switch1;
  bool doorContactState;
  int countdown1;
  int countdownAlarm;
  String doorControl1;
  bool voiceControl1;
  String doorState1;
  int batteryPercentage;
  int tr_timecon;

  GarageDoorModel({
    required this.switch1,
    required this.doorContactState,
    required this.countdown1,
    required this.countdownAlarm,
    required this.doorControl1,
    required this.voiceControl1,
    required this.doorState1,
    required this.batteryPercentage,
    required this.tr_timecon,
  });

  factory GarageDoorModel.fromJson(List<StatusModel> jsonList) {
    bool _switch1 = false;
    bool _doorContactState = false;
    int _countdown1 = 0;
    int _countdownAlarm = 0;
    String _doorControl1 = "closed";
    bool _voiceControl1 = false;
    String _doorState1 = "closed";
    int _batteryPercentage = 0;
    int _tr_timecon = 0;

    for (var status in jsonList) {
      switch (status.code) {
        case 'tr_timecon':
          _tr_timecon = status.value ?? "closed";
          break;
        case 'switch_1':
          _switch1 = status.value ?? false;
          break;
        case 'doorcontact_state':
          _doorContactState = status.value ?? false;
          break;
        case 'countdown_1':
          _countdown1 = status.value ?? 0;
          break;
        case 'countdown_alarm':
          _countdownAlarm = status.value ?? 0;
          break;
        case 'door_control_1':
          _doorControl1 = status.value ?? "closed";
          break;

        case 'voice_control_1':
          _voiceControl1 = status.value ?? false;
          break;
        case 'door_state_1':
          _doorState1 = status.value ?? "closed";
          break;
        case 'battery_percentage':
          _batteryPercentage = status.value ?? 0;
          break;
      }
    }

    return GarageDoorModel(
        switch1: _switch1,
        doorContactState: _doorContactState,
        countdown1: _countdown1,
        countdownAlarm: _countdownAlarm,
        doorControl1: _doorControl1,
        voiceControl1: _voiceControl1,
        doorState1: _doorState1,
        batteryPercentage: _batteryPercentage,
        tr_timecon: _tr_timecon);
  }
}
