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 'package:making_school_asignment_app/common/store/user_store.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 {
    params.pageNumber = state.pageNumber;
    WorkStudent data = await getClient().getUnAnnotateList(params);
    state.totalCount.value = data.totalCount;
    state.readOver.value = data.items.length;
    if(params.pageNumber == 1){
      state.workList.value = data.items;
    }else{
      state.workList.addAll(data.items);
    }
    refreshController.finishRefresh();
  }

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