import 'package:ef/ef.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vbvs_app/controller/device/body_device_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';

part 'home_controller.g.dart'; // 由json_serializable自动生成的部分

@JsonSerializable()
class HomeModel {
  int? type = 1; //我的e护 2.云关爱

  HomeModel();

  // 从JSON反序列化时的异常处理

  factory HomeModel.fromJson(Map<String, dynamic> json) {
    try {
      return _$HomeModelFromJson(json);
    } catch (e) {
      // 在实际应用中，应该有更细致的异常处理策略和错误日志
      return HomeModel(); // 或者返回一个带有错误信息的特定DeviceInfoModel实例
    }
  }

  // 序列化为JSON时的异常处理
  Map<String, dynamic> toJson() => _$HomeModelToJson(this);
}

class HomeController extends GetControllerEx<HomeModel> {

  UserInfoController userInfoController = Get.find(); 
  ThemeController themeController = Get.find();
  BodyDeviceController deviceController = Get.find();
  @override
  void onInit() {
    super.onInit();    
  }

  HomeController() {
    attr = GetModel(HomeModel()).obs;
  }

  RxInt sleepNum = 0.obs;

  getSleepReport() {
    sleepNum.value = 5;
    updateAll();
  }
}
