import 'package:domain/entity/response/hotel_info_entity.dart';
import 'package:domain/entity/response/job_list_add_staff_entity.dart';
import 'package:domain/entity/response/job_list_e_r_detail_entity.dart';
import 'package:domain/entity/response/job_list_e_r_option_entity.dart';
import 'package:domain/entity/response/labour_request_e_r_entity.dart';
import 'package:domain/entity/response/sign_in_sign_out_entity.dart';
import 'package:domain/entity/response/switch_project_entity.dart';
import 'package:domain/entity/response/t_h_applied_edit_entity.dart';
import 'package:domain/entity/response/t_h_applied_employee_entity.dart';
import 'package:domain/entity/response/t_h_applied_index_entity.dart';
import 'package:domain/entity/response/t_h_applied_table_entity.dart';
import 'package:get/get.dart';
import 'package:plugin_platform/http/http_provider.dart';
import 'package:plugin_platform/http/http_result.dart';
import 'package:plugin_platform/platform_export.dart';
import 'package:shared/utils/util.dart';

import '../constants/api_constants.dart';
import '../entity/response/job_list_applied_work_flow_entity.dart';
import '../entity/response/job_list_remark_view_entity.dart';
import '../entity/response/labour_list_e_r_entity.dart';
import '../entity/response/labour_request_e_r_option_entity.dart';
import '../entity/response/staff_detail_entity.dart';
import '../entity/response/staff_labour_history_entity.dart';
import '../entity/response/staff_remark_history_entity.dart';
import '../entity/response/t_h_employee_detail_entity.dart';
import '../entity/response/t_h_employee_remarks_entity.dart';
import '../entity/response/t_h_pre_selected_option_entity.dart';
import '../entity/response/t_h_pre_selected_staff_table_entity.dart';
import '../entity/response/t_h_pre_selected_table_entity.dart';

/// 泰国的 ER 的数据仓库
class THERRepository extends GetxService {
  HttpProvider httpProvider;

  THERRepository({required this.httpProvider});

  /// 获取 ER 用工请求列表
  Future<HttpResult<LabourRequestEREntity>> fetchERLabourRequest(
    String? date, {
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    if (!Utils.isEmpty(date)) {
      params["day"] = date!;
    }
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERLabourRequestTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = LabourRequestEREntity.fromJson(json!);
      return result.convert<LabourRequestEREntity>(data: data);
    }
    return result.convert();
  }

  /// 获取 ER 用工请求选项
  Future<HttpResult<JobListERDetailEntity>> fetchERLabourRequestAddOption({
    CancelToken? cancelToken,
  }) async {
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERLabourRequestAddOptionTH,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = JobListERDetailEntity.fromJson(json!);
      return result.convert<JobListERDetailEntity>(data: data);
    }
    return result.convert();
  }

  /// 新增 ER 的用工请求
  Future<HttpResult> addLabourRequestERSubmit({
    required String jobTitleId,
    required String startTime,
    required String endTime,
    required String outletId,
    String? repeatStart,
    String? repeatEnd,
    String? sexLimit,
    String? needNum,
    String? maleLimit,
    String? femaleLimit,
    String? eventName,
    String? eventType,
    String? remark,
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["job_title_id"] = jobTitleId;
    params["start_time"] = startTime;
    params["end_time"] = endTime;
    params["outlet_id"] = outletId;
    if (!Utils.isEmpty(repeatStart)) {
      params["repeat_start"] = repeatStart!;
    }
    if (!Utils.isEmpty(repeatEnd)) {
      params["repeat_end"] = repeatEnd!;
    }

    params['sex_limit'] = sexLimit ?? "0";
    if (sexLimit == "1") {
      params['male_limit'] = maleLimit ?? "0";
      params['female_limit'] = femaleLimit ?? "0";
    } else {
      params['need_num'] = needNum ?? "0";
    }

    if (!Utils.isEmpty(eventName)) {
      params["event_name"] = eventName!;
    }
    if (!Utils.isEmpty(eventType)) {
      params["event_type"] = eventType!;
    }
    if (!Utils.isEmpty(remark)) {
      params["remark"] = remark!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERLabourRequestAddSubmitTH,
      method: HttpMethod.POST,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  /// 获取 ER 工作列表选项
  Future<HttpResult<JobListEROptionEntity>> fetchERJobListOption({
    String? date,
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    if (!Utils.isEmpty(date)) {
      params["daily"] = date!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERJobListOptionTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = JobListEROptionEntity.fromJson(json!);
      return result.convert<JobListEROptionEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取 ER 工作列表
  Future<HttpResult<LabourListEREntity>> fetchERJobListTable({
    required int curPage,
    String? keyword,
    String? divisionId,
    String? outletId,
    String? status,
    String? startDate,
    String? endDate,
    String? trending,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";
    if (!Utils.isEmpty(keyword)) {
      params["job_title"] = keyword!;
    }
    if (!Utils.isEmpty(divisionId)) {
      params["division_id"] = divisionId!;
    }
    if (!Utils.isEmpty(outletId)) {
      params["outlet_id"] = outletId!;
    }
    if (!Utils.isEmpty(status)) {
      params["status"] = status!;
    }
    if (!Utils.isEmpty(startDate)) {
      params["start_date"] = startDate!;
    }
    if (!Utils.isEmpty(endDate)) {
      params["end_date"] = endDate!;
    }
    if (!Utils.isEmpty(trending)) {
      params["trending"] = trending!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERJobListTableTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = LabourListEREntity.fromJson(json!);
      return result.convert<LabourListEREntity>(data: data);
    }
    return result.convert();
  }

  ///  ER 工作列表的删除
  Future<HttpResult> deleteJobListERSubmit({
    required String jobId,
    required String type,
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["job_id"] = jobId;
    params["type"] = type;

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERJobListDeleteTH,
      method: HttpMethod.POST,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  /// 获取 ER 工作列表详情
  Future<HttpResult<JobListERDetailEntity>> fetchERJobListDetail({
    required String jobId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["job_id"] = jobId;

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERJobListDetailTH,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = JobListERDetailEntity.fromJson(json!);
      return result.convert<JobListERDetailEntity>(data: data);
    }
    return result.convert();
  }

  /// 编辑 ER 的用工请求
  Future<HttpResult> editLabourRequestERSubmit({
    required String jobId,
    required String jobTitleId,
    required String startTime,
    required String endTime,
    required String outletId,
    String? sexLimit,
    String? needNum,
    String? maleLimit,
    String? femaleLimit,
    String? eventName,
    String? eventType,
    String? remark,
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["job_id"] = jobId;
    params["job_title_id"] = jobTitleId;
    params["start_time"] = startTime;
    params["end_time"] = endTime;
    params["outlet_id"] = outletId;
    if (!Utils.isEmpty(sexLimit)) {
      params["sex_limit"] = sexLimit!;
    }
    if (!Utils.isEmpty(needNum)) {
      params["need_num"] = needNum!;
    }
    if (!Utils.isEmpty(maleLimit)) {
      params["male_limit"] = maleLimit!;
    }
    if (!Utils.isEmpty(femaleLimit)) {
      params["female_limit"] = femaleLimit!;
    }
    if (!Utils.isEmpty(eventName)) {
      params["event_name"] = eventName!;
    }
    if (!Utils.isEmpty(eventType)) {
      params["event_type"] = eventType!;
    }
    if (!Utils.isEmpty(remark)) {
      params["remark"] = remark!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERLabourRequestEditSubmitTH,
      method: HttpMethod.POST,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  /// 获取 ER 工作 Applied 选项
  Future<HttpResult<THAppliedIndexEntity>> fetchERAppliedOption({
    required String? jobId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["job_id"] = jobId ?? "";

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedOptionTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THAppliedIndexEntity.fromJson(json!);
      return result.convert<THAppliedIndexEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取 ER 工作 Applied Table
  Future<HttpResult<THAppliedTableEntity>> fetchERAppliedTable({
    required String? jobId,
    required int curPage,
    String? keyword,
    String? status,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["job_id"] = jobId ?? "";
    params["cur_page"] = curPage.toString();
    params["page_size"] = '10';
    if (!Utils.isEmpty(keyword)) {
      params["keyword"] = keyword!;
    }
    if (!Utils.isEmpty(status)) {
      params["status"] = status!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedListTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THAppliedTableEntity.fromJson(json!);
      return result.convert<THAppliedTableEntity>(data: data);
    }
    return result.convert();
  }

  // 刷新 Table
  Future<HttpResult<THAppliedTableEntity>> fetchItemByAppliedIds(
    String? jobId,
    String? appliedIds, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = "1";
    params["page_size"] = "9999";
    if (!Utils.isEmpty(appliedIds)) {
      params["applied_ids"] = appliedIds!;
    }
    if (!Utils.isEmpty(jobId)) {
      params["job_id"] = jobId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedListTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THAppliedTableEntity.fromJson(json!);
      return result.convert<THAppliedTableEntity>(data: data);
    }
    return result.convert();
  }

  /// Applied 批量员工批准
  Future<HttpResult> submitBatchStaffApprove(String? separatedIds, {required CancelToken cancelToken}) async {
    Map<String, String> params = {};
    params["applied_ids"] = separatedIds ?? "";

    final result = await httpProvider.requestNetResult(
      method: HttpMethod.POST,
      ApiConstants.apiERAppliedApproveTH,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  /// Applied 批量员工编辑
  Future<HttpResult> batchEditStaffCheckTime(String? separatedIds, String? startDate, String? endDate, {required CancelToken cancelToken}) async {
    Map<String, String> params = {};
    params["applied_ids"] = separatedIds ?? "";
    if (!Utils.isEmpty(startDate)) {
      params["start_time"] = startDate!;
    }
    if (!Utils.isEmpty(endDate)) {
      params["end_time"] = endDate!;
    }

    final result = await httpProvider.requestNetResult(
      method: HttpMethod.POST,
      ApiConstants.apiERAppliedEditTH,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  /// 获取 ER 工作 Applied 编辑详情
  Future<HttpResult<THAppliedEditEntity>> fetchERAppliedEditDetail({
    required String? appliedId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["applied_id"] = appliedId ?? "";

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedEditAttTH,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THAppliedEditEntity.fromJson(json!);
      return result.convert<THAppliedEditEntity>(data: data);
    }
    return result.convert();
  }

  /// Applied 修改员工考勤提交
  Future<HttpResult> editAppliedDetailSubmit({
    required String? appliedId,
    String? startTime,
    String? endTime,
    String? securityIn,
    String? securityOut,
    String? workIn,
    String? workOut,
    String? subtractHours,
    String? status,
    String? reasonType,
    String? remark,
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["applied_id"] = appliedId ?? "";
    if (!Utils.isEmpty(startTime)) {
      params["start_time"] = startTime!;
    }
    if (!Utils.isEmpty(endTime)) {
      params["end_time"] = endTime!;
    }
    if (!Utils.isEmpty(securityIn)) {
      params["security_in"] = securityIn!;
    }
    if (!Utils.isEmpty(securityOut)) {
      params["security_out"] = securityOut!;
    }
    if (!Utils.isEmpty(workIn)) {
      params["work_in"] = workIn!;
    }
    if (!Utils.isEmpty(workOut)) {
      params["work_out"] = workOut!;
    }
    if (!Utils.isEmpty(subtractHours)) {
      params["subtract_hours"] = subtractHours!;
    }
    if (!Utils.isEmpty(status)) {
      params["status"] = status!;
    }
    if (!Utils.isEmpty(reasonType)) {
      params["reason_type"] = reasonType!;
    }
    if (!Utils.isEmpty(remark)) {
      params["remark"] = remark!;
    }

    final result = await httpProvider.requestNetResult(
      method: HttpMethod.POST,
      ApiConstants.apiERAppliedEditAttSubmitTH,
      params: params,
      networkDebounce: true,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  /// 添加员工的全部员工数据列表
  Future<HttpResult<THAppliedEmployeeEntity>> searchStaffList(
    String? jobId,
    String? keyword, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    if (Utils.isNotEmpty(jobId)) {
      params["job_id"] = jobId!;
    }
    if (Utils.isNotEmpty(keyword)) {
      params["keyword"] = keyword!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedAddEmployeeTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THAppliedEmployeeEntity.fromJson(json!);
      return result.convert<THAppliedEmployeeEntity>(data: data);
    }
    return result.convert();
  }

  /// 添加员工到工作
  Future<HttpResult<JobListAddStaffEntity>> addStaff2Job(
    String? jobId,
    String? staffIds, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(jobId)) {
      params["job_id"] = jobId!;
    }
    if (!Utils.isEmpty(staffIds)) {
      params["staff_ids"] = staffIds!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedAddEmployeeSubmitTH,
      isShowLoadingDialog: true,
      method: HttpMethod.POST,
      params: params,
      cancelToken: cancelToken,
    );
    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = JobListAddStaffEntity.fromJson(json!);
      return result.convert<JobListAddStaffEntity>(data: data);
    }
    return result.convert();
  }

  // 员工的信息
  Future<HttpResult<THEmployeeDetailEntity>> fetchStaffDetail(
    String? memberId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(memberId)) {
      params["member_id"] = memberId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiEREmployeeInfoTH,
      params: params,
      cancelToken: cancelToken,
    );

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = THEmployeeDetailEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<THEmployeeDetailEntity>(data: data);
    }
    return result.convert();
  }

  // 员工的历史申请记录
  Future<HttpResult<StaffLabourHistoryEntity>> fetchStaffLabourHistory(
    String? memberId,
    String? keyword, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    if (!Utils.isEmpty(memberId)) {
      params["member_id"] = memberId!;
    }

    if (!Utils.isEmpty(keyword)) {
      params["keyword"] = keyword!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiEREmployeeHistoryTH,
      params: params,
      cancelToken: cancelToken,
    );

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = StaffLabourHistoryEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<StaffLabourHistoryEntity>(data: data);
    }
    return result.convert();
  }

  // 员工的历史评价记录
  Future<HttpResult<THEmployeeRemarksEntity>> fetchStaffRemarkHistory(
    String? memberId, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    if (!Utils.isEmpty(memberId)) {
      params["member_id"] = memberId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiEREmployeeEvaluationTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THEmployeeRemarksEntity.fromJson(json!);
      return result.convert<THEmployeeRemarksEntity>(data: data);
    }
    return result.convert();
  }

  /// 给员工评分的详情与选项
  Future<HttpResult<JobListRemarkViewEntity>> fetchAppliedStaffReviewView(
    String? appliedId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(appliedId)) {
      params["applied_id"] = appliedId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedStaffReviewIndexTH,
      isShowLoadingDialog: true,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = JobListRemarkViewEntity.fromJson(json!);
      return result.convert<JobListRemarkViewEntity>(data: data);
    }
    return result.convert();
  }

  /// 单独给单个员工评分的提交
  Future<HttpResult> remarkAppliedSingleStaffSubmit(
    String? appliedId,
    String? attitudeRate,
    String? groomingRate,
    String? performanceRate,
    String? experienceRate,
    String? content, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, dynamic> params = {};
    if (!Utils.isEmpty(appliedId)) {
      params["applied_id"] = appliedId!;
    }
    if (!Utils.isEmpty(attitudeRate)) {
      params["attitude_rate"] = (double.parse(attitudeRate!)).toInt();
    }
    if (!Utils.isEmpty(groomingRate)) {
      params["grooming_rate"] = (double.parse(groomingRate!)).toInt();
    }
    if (!Utils.isEmpty(performanceRate)) {
      params["performance_rate"] = (double.parse(performanceRate!)).toInt();
    }
    if (!Utils.isEmpty(experienceRate)) {
      params["experience_rate"] = (double.parse(experienceRate!)).toInt();
    }
    if (!Utils.isEmpty(content)) {
      params["feedback"] = content!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedStaffReviewSubmitTH,
      isShowLoadingDialog: true,
      method: HttpMethod.POST,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  // 员工状态的工作流
  Future<HttpResult<JobListAppliedWorkFlowEntity>> fetchAppliedWorkFlow(
    String? appliedId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(appliedId)) {
      params["applied_id"] = appliedId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERAppliedStaffStateWorkflowTH,
      params: params,
      cancelToken: cancelToken,
    );

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = JobListAppliedWorkFlowEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<JobListAppliedWorkFlowEntity>(data: data);
    }
    return result.convert();
  }

  // 预选员工选项
  Future<HttpResult<THPreSelectedOptionEntity>> fetchPreSelectedOption({
    String? requestId,
    String? jobId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(requestId)) {
      params["request_id"] = requestId!;
    }
    if (!Utils.isEmpty(jobId)) {
      params["job_id"] = jobId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERPreSelectOptionTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THPreSelectedOptionEntity.fromJson(json!);
      return result.convert<THPreSelectedOptionEntity>(data: data);
    }
    return result.convert();
  }

  // 预选员工列表
  Future<HttpResult<THPreSelectedTableEntity>> fetchPreSelectedTable({
    String? requestId,
    String? jobId,
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(requestId)) {
      params["request_id"] = requestId!;
    }
    if (!Utils.isEmpty(jobId)) {
      params["job_id"] = jobId!;
    }
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERPreSelectTableTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THPreSelectedTableEntity.fromJson(json!);
      return result.convert<THPreSelectedTableEntity>(data: data);
    }
    return result.convert();
  }

  // 预选员工-员工列表
  Future<HttpResult<THPreSelectedStaffTableEntity>> fetchPreSelectedStaffTable({
    String? requestId,
    String? jobId,
    String? keyword,
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(requestId)) {
      params["request_id"] = requestId!;
    }
    if (!Utils.isEmpty(jobId)) {
      params["job_id"] = jobId!;
    }
    if (!Utils.isEmpty(keyword)) {
      params["keyword"] = keyword!;
    }
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERPreSelectStaffTableTH,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      final json = result.getDataJson();
      var data = THPreSelectedStaffTableEntity.fromJson(json!);
      return result.convert<THPreSelectedStaffTableEntity>(data: data);
    }
    return result.convert();
  }

  //预选添加员工
  Future<HttpResult> submitStaff2PreSelected({
    String? requestId,
    String? jobId,
    String? staffIds,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, dynamic> params = {};
    if (!Utils.isEmpty(requestId)) {
      params["request_id"] = requestId!;
    }
    if (!Utils.isEmpty(jobId)) {
      params["job_id"] = jobId!;
    }
    if (!Utils.isEmpty(staffIds)) {
      params["staff_ids"] = staffIds!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERPreSelectAddEmployeeTH,
      isShowLoadingDialog: true,
      method: HttpMethod.POST,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

  //预选删除员工
  Future<HttpResult> deleteStaffFormPreSelected({
    String? selectedId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, dynamic> params = {};
    if (!Utils.isEmpty(selectedId)) {
      params["selected_id"] = selectedId!;
    }

    final result = await httpProvider.requestNetResult(
      ApiConstants.apiERPreSelectDeleteEmployeeTH,
      isShowLoadingDialog: true,
      method: HttpMethod.POST,
      params: params,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      return result.convert();
    }
    return result.convert();
  }

}
