import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/job/work_student.dart';
import 'package:making_school_asignment_app/common/job/work_student_params.dart';
import 'package:making_school_asignment_app/common/mixins/request_tool_mixin.dart';

import 'home_state.dart';

class HomeLogic extends GetxController with RequestToolMixin, GetTickerProviderStateMixin {
  final HomeState state = HomeState();
  late final EasyRefreshController refreshController;
  WorkStudentParams params = WorkStudentParams(
    assessType: 0,
  );

  @override
  void onInit() {
    super.onInit();
    refreshController = EasyRefreshController();
    params.pageSize = state.pageSize;

    getList();
  }

  void getList() async {
    try {
      params.pageNumber = state.pageNumber;
      WorkStudent data = await getClient().getUnAnnotateList(params);
      state.totalCount.value = data.totalCount;
      state.readOver.value = data.items.length;

      // 完成刷新
      refreshController.finishRefresh();
    } catch (e) {
      print('获取作业列表失败: $e');
      // 完成刷新并显示错误
      refreshController.finishRefresh();
      // 可以在这里添加错误提示
    }
  }

  @override
  void dispose() {
    super.dispose();
    refreshController.dispose();
  }
}
