import 'package:syncrow_app/features/devices/model/status_model.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; class ThreeTouchModel { bool firstSwitch; bool secondSwitch; bool thirdSwitch; int firstCountDown; int secondCountDown; int thirdCountDown; status relay; lightStatus light_mode; status relay_status_1; status relay_status_2; status relay_status_3; ThreeTouchModel( {required this.firstSwitch, required this.secondSwitch, required this.thirdSwitch, required this.firstCountDown, required this.secondCountDown, required this.thirdCountDown, required this.light_mode, required this.relay, required this.relay_status_1, required this.relay_status_2, required this.relay_status_3}); factory ThreeTouchModel.fromJson(List jsonList) { late bool _firstSwitch; late bool _secondSwitch; late bool _thirdSwitch; late int _firstCount; late int _secondCount; late int _thirdCount; late String _relay; late String _light_mode; late String _relay_status_1; late String _relay_status_2; late String _relay_status_3; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'switch_1') { _firstSwitch = jsonList[i].value ?? false; } else if (jsonList[i].code == 'switch_2') { _secondSwitch = jsonList[i].value ?? false; } else if (jsonList[i].code == 'switch_3') { _thirdSwitch = jsonList[i].value ?? false; } else if (jsonList[i].code == 'countdown_1') { _firstCount = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'countdown_2') { _secondCount = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'countdown_3') { _thirdCount = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'relay_status') { _relay = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'light_mode') { _light_mode = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'relay_status_1') { _relay_status_1 = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'relay_status_2') { _relay_status_2 = jsonList[i].value ?? 0; } else if (jsonList[i].code == 'relay_status_3') { _relay_status_3 = jsonList[i].value ?? 0; } } return ThreeTouchModel( firstSwitch: _firstSwitch, secondSwitch: _secondSwitch, thirdSwitch: _thirdSwitch, firstCountDown: _firstCount, secondCountDown: _secondCount, thirdCountDown: _thirdCount, light_mode: lightStatusExtension.fromString(_light_mode), relay: StatusExtension.fromString(_relay), relay_status_1: StatusExtension.fromString(_relay_status_1), relay_status_2: StatusExtension.fromString(_relay_status_2), relay_status_3: StatusExtension.fromString(_relay_status_3)); } }