import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; enum TempModes { hot, cold, wind } enum FanSpeeds { auto, low, middle, high } class AcStatusModel { final String uuid; final bool acSwitch; final String modeString; final int tempSet; final int currentTemp; final String fanSpeedsString; final bool childLock; final TempModes acMode; final FanSpeeds acFanSpeed; AcStatusModel({ required this.uuid, required this.acSwitch, required this.modeString, required this.tempSet, required this.currentTemp, required this.fanSpeedsString, required this.childLock, }) : acMode = getACMode(modeString), acFanSpeed = getFanSpeed(fanSpeedsString); factory AcStatusModel.fromJson(String id, List jsonList) { late bool acSwitch; late String mode; late int tempSet; late int currentTemp; late String fanSpeeds; late bool childLock; for (var status in jsonList) { switch (status.code) { case 'switch': acSwitch = status.value ?? false; break; case 'mode': mode = status.value ?? 'cold'; // default to 'cold' if null break; case 'temp_set': tempSet = status.value ?? 210; // default value if null break; case 'temp_current': currentTemp = status.value ?? 210; // default value if null break; case 'level': fanSpeeds = status.value ?? 'low'; // default value if null break; case 'child_lock': childLock = status.value ?? false; break; } } return AcStatusModel( uuid: id, acSwitch: acSwitch, modeString: mode, tempSet: tempSet, currentTemp: currentTemp, fanSpeedsString: fanSpeeds, childLock: childLock, ); } AcStatusModel copyWith({ String? uuid, bool? acSwitch, String? modeString, int? tempSet, int? currentTemp, String? fanSpeedsString, bool? childLock, }) { return AcStatusModel( uuid: uuid ?? this.uuid, acSwitch: acSwitch ?? this.acSwitch, modeString: modeString ?? this.modeString, tempSet: tempSet ?? this.tempSet, currentTemp: currentTemp ?? this.currentTemp, fanSpeedsString: fanSpeedsString ?? this.fanSpeedsString, childLock: childLock ?? this.childLock, ); } static TempModes getACMode(String value) { switch (value) { case 'cold': return TempModes.cold; case 'hot': return TempModes.hot; case 'wind': return TempModes.wind; default: return TempModes.cold; } } static FanSpeeds getFanSpeed(String value) { switch (value) { case 'low': return FanSpeeds.low; case 'middle': return FanSpeeds.middle; case 'high': return FanSpeeds.high; case 'auto': return FanSpeeds.auto; default: return FanSpeeds.auto; } } }