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/annotated_class.dart';
import 'package:making_school_asignment_app/common/mixins/request_tool_mixin.dart';

import 'answer_trajectory_detail_state.dart';

class AnswerTrajectoryDetailLogic extends GetxController with RequestToolMixin{
  final AnswerTrajectoryDetailState state = AnswerTrajectoryDetailState();
  late final EasyRefreshController refreshController;
  @override
  void onInit(){
    super.onInit();
    state.homeworkId.value = Get.arguments['homeworkId'] ?? '';
    state.title.value = Get.arguments['title'] ?? '';
    state.grade = Get.arguments['grade'] ?? -1;
    state.subject = Get.arguments['subject'] ?? -1;
    refreshController = EasyRefreshController();
    EasyLoading.show(status: 'loading...');
    getList();
  }

  void getList() async{
    List<AnnotatedClass> data = await getClient().getAnnotatedClassList(state.homeworkId.value);
    state.classList.value = data;
    if( state.classList.isNotEmpty){
      state.currentClass.value = state.classList[0];
    }
    EasyLoading.dismiss();
  }

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