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

import 'quick_data_check_state.dart';

class QuickDataCheckLogic extends GetxController with RequestToolMixin {
  final QuickDataCheckState state = QuickDataCheckState();

  @override
  void onInit() {
    super.onInit();
    state.homeworkId.value = Get.arguments['homeworkId'] ?? '';
    state.classId.value = Get.arguments['classId'] ?? '';
    state.className.value = Get.arguments['className'] ?? '';
    state.grade = Get.arguments['grade'];
    EasyLoading.show(status: 'loading...');
    getWorkData();
  }

  void getWorkData() async {
    HomeworkDetails data = await getClient().getHomeworkDetails(state.homeworkId.value, state.classId.value);
    EasyLoading.dismiss();
    state.subject = data.subject!;
    state.dataCount = Utils.getHomeworkData(data);
    state.homeData = data;
    state.kgReport.value = data.questions.where((w) => w.questionType == 1).toList();
    state.zgReport.value = data.questions.where((w) => w.questionType == 2).toList();
    state.studentList.value = data.students;
    state.hasData.value = true;

  }
}
