import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/job/homework_details.dart';
import 'package:making_school_asignment_app/common/job/knowledge_report_detail.dart';
import 'package:making_school_asignment_app/common/mixins/request_tool_mixin.dart';

import 'knowledge_points_grasp_detail_state.dart';

class KnowledgePointsGraspDetailLogic extends GetxController with RequestToolMixin {
  final KnowledgePointsGraspDetailState state = KnowledgePointsGraspDetailState();
  late final EasyRefreshController refreshController;

  @override
  void onInit() {
    super.onInit();
    state.dateStart = Get.arguments['dateStart'];
    state.dateEnd = Get.arguments['dateEnd'];
    state.knowledgeId = Get.arguments['knowledgeId'];
    state.knowledgeName.value = Get.arguments['knowledgeName'];
    state.subject = Get.arguments['subject'] ?? -1;
    refreshController = EasyRefreshController();
    EasyLoading.show(status: 'loading...');
    getList();
  }

  void getList() async {
    List<KnowledgeReportDetail> data = await getClient().getKnowledgeReportDetail(state.dateStart, state.dateEnd, state.knowledgeId);
    state.dataList.value = data;
    EasyLoading.dismiss();
  }

  getStudents(homeworkId, templateId, questionNo) async {
    List<Students> data = await getClient().getQuestionStudentState(homeworkId, templateId, questionNo);
    state.studentList.value = data;
  }

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