import 'package:domain/repository/job_repository.dart';
import 'package:get/get.dart';
import 'package:plugin_platform/engine/toast/toast_engine.dart';
import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
import 'job_list_detail_state.dart';

class JobListDetailController extends GetxController with DioCancelableMixin {
  final JobRepository _jobRepository = Get.find();
  final JobListDetailState state = JobListDetailState();


  /// 获取工作详情数据
  void fetchJobListDetail() async {
    var result = await _jobRepository.fetchJobListDetail(
      state.jobId,
      cancelToken: cancelToken,
    );

    //处理数据
    if (result.isSuccess) {
      state.jobListDetail = result.data;
      state.selectedStartTime = state.jobListDetail?.startTime;
      state.selectedEndTime = state.jobListDetail?.endTime;
      state.noStaff = state.jobListDetail?.needNum.toString() == "0" ? "" : state.jobListDetail?.needNum.toString();
      var needNumController = state.formData['no_of_staff']!['controller'];
      needNumController.text = state.noStaff;
      state.selectedJobTitle = state.jobListDetail?.jobTitle;
      state.selectedDepartmentId = state.jobListDetail?.departmentId;

      update();
    } else {
      ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
    }
  }

  @override
  void onReady() {
    super.onReady();
    fetchJobListDetail();
  }

}
