import 'package:anchor_collect_flutter/models/cattle_resume_entity.dart';
import 'package:anchor_collect_flutter/models/dict_entity.dart';
import 'package:anchor_collect_flutter/models/user_model.dart';
import 'package:get/get.dart';
import 'package:isar/isar.dart';

import '../../controllers/global_service.dart';
import '../../routes/routes.dart';

class HomeLogic extends GetxController {
  late RxString username = ''.obs;
  late String password = '';

  late RxInt breedingCount = 0.obs;
  late RxInt obsoleteCount = 0.obs;
  late RxInt deadCount = 0.obs;
  late RxInt sellCount = 0.obs;

  @override
  void onReady() {
    // var map = Get.arguments;
    // username.value = map['username'];
    // password = map['password'];
    //
    // update();
  }

  ///获取游客令牌

  void getVisitorToken() async {
    Map<String, String> headMap = {};

    headMap.putIfAbsent('client-version', () => '2.1.1');
    headMap.putIfAbsent('client-channel', () => '1');

    Map<String, String> map = {}; //参数
    String strMd5 = '';

    map.putIfAbsent('code', () => '');
    map.putIfAbsent('userType', () => 'Tourist');
    String apiKey = 'kangeqiu@8868!';
    map.putIfAbsent('from', () => 'GW');

    // RequestClient().post<UserInfo>(APIS.login_getMsg, //url 地址
    //     //是否显示加载中
    //     showLoading: false,
    //     //参数
    //     data: map,
    //     //单个请求添加head
    //     headers: headMap,
    //     onResponse: (response) {
    //       // response.address
    //     },
    //     onError: (e) {
    //
    //       return true; //false 表示没有处理移除  ture 表示处理了异常   默认值 false
    //     }
    // );
  }

  getBreedingCount() async {
    breedingCount.value = await GlobalService.to.isar.cattleResumeEntitys.filter().statusEqualTo('1').count();
    obsoleteCount.value = await GlobalService.to.isar.cattleResumeEntitys.filter().statusEqualTo('2').count();
    deadCount.value = await GlobalService.to.isar.cattleResumeEntitys.filter().statusEqualTo('3').count();
    sellCount.value = await GlobalService.to.isar.cattleResumeEntitys.filter().statusEqualTo('4').count();
  }

  forWard(String title) {
    switch (title) {
      case '基础信息':
        Get.toNamed(AppRoute.CATTLE_RESUME_LIST);
        break;
      case '性能测定':
        break;
      case '诊疗记录':
        break;
      case '配种记录':
        break;
      case '免疫记录':
        break;
      case '称重管理':
        break;
    }
  }

  @override
  void onInit() {
    getBreedingCount();
    // update();
  }
}
