import 'dart:typed_data';
import 'package:domain/entity/response/job_applied_index_s_g_entity.dart';
import 'package:domain/entity/response/job_applied_list_s_g_entity.dart';
import 'package:domain/entity/response/revise_list_s_g_entity.dart';
import 'package:domain/entity/response/revise_log_s_g_entity.dart';
import 'package:domain/entity/response/s_g_attendance_review_option_entity.dart';
import 'package:domain/entity/response/s_g_attendance_review_table_entity.dart';
import 'package:domain/entity/response/s_g_attendance_review_workflow_entity.dart';
import 'package:domain/entity/response/s_g_dashboard_entity.dart';
import 'package:domain/entity/response/staff_detail_s_g_entity.dart';
import 'package:domain/entity/response/staff_review_history_s_g_entity.dart';
import 'package:get/get.dart';
import 'package:plugin_platform/platform_export.dart';
import 'package:plugin_platform/http/http_provider.dart';
import 'package:plugin_platform/http/http_result.dart';
import 'package:shared/utils/date_time_utils.dart';
import 'package:shared/utils/util.dart';
import '../constants/api_constants.dart';
import '../entity/response/add_edit_revise_view_s_g_entity.dart';
import '../entity/response/job_applied_edit_index_s_g_entity.dart';
import '../entity/response/job_applied_remark_view_s_g_entity.dart';
import '../entity/response/job_applied_staff_s_g_entity.dart';
import '../entity/response/revise_index_s_g_entity.dart';
import '../entity/response/staff_job_history_s_g_entity.dart';

/// 工作相关(新加坡)
class JobSGRepository extends GetxService {
  HttpProvider httpProvider;

  JobSGRepository({required this.httpProvider});

  /// 获取工作已申请的选项
  Future<HttpResult<JobAppliedIndexSGEntity>> fetchJobAppliedIndex(
    String? jobId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["job_id"] = jobId ?? "";

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

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

  /// 获取工作已申请的列表
  Future<HttpResult<JobAppliedListSGEntity>> fetchJobAppliedList(
    String? jobId,
    String? status,
    String? keyword, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";
    params["job_id"] = jobId ?? "";

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

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

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

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

  /// 根据ID获取主列表的Item数据，用于刷新Item
  Future<HttpResult<JobAppliedListSGEntity>> 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.apiJobAppliedListSG,
      params: params,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

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

  /// 获取工作已申请的列表中添加的员工搜索
  Future<HttpResult<JobAppliedStaffSGEntity>> searchJobAppliedStaff(
    String? jobId,
    String? keyword, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "20";
    params["job_id"] = jobId ?? "";

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

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

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

  /// 添加员工到申请列表
  Future<HttpResult> addStaff2AppliedJob(
    String? jobId,
    String? staffIds, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['job_id'] = jobId ?? "";
    params['staff_ids'] = staffIds ?? "";

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 批量修改员工信息或考勤
  Future<HttpResult> batchEditJobApplied(
    String? jobId,
    String? appliedIds,
    String? startTime,
    String? endTime,
    String? subtractHours,
    String? status, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_ids'] = appliedIds ?? "";
    params['job_id'] = jobId ?? "";

    if (!Utils.isEmpty(startTime)) {
      params['start_time'] = startTime ?? "";
    }
    if (!Utils.isEmpty(endTime)) {
      params['end_time'] = endTime ?? "";
    }
    if (!Utils.isEmpty(subtractHours)) {
      params['subtract_hours'] = subtractHours ?? "";
    }
    if (!Utils.isEmpty(status)) {
      params['status'] = status ?? "";
    }

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 编辑员工信息或考勤的选项详情
  Future<HttpResult<JobAppliedEditIndexSGEntity>> fetchEditJobAppliedIndex(
    String? appliedId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";

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

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

  /// 编辑员工信息或考勤的提交
  Future<HttpResult> submitEditJobApplied(
    String? appliedId,
    String? startTime,
    String? endTime,
    String? security_in,
    String? security_out,
    String? work_in,
    String? work_out,
    String? adjustHours,
    String? status, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";
    params['start_time'] = DateTimeUtils.formatDateStr(startTime!, format: 'HH:mm:ss') ?? "";
    params['end_time'] = DateTimeUtils.formatDateStr(endTime!, format: 'HH:mm:ss') ?? "";

    if (!Utils.isEmpty(security_in)) {
      params['security_in'] = DateTimeUtils.formatDateStr(security_in!, format: 'HH:mm:ss');
    }
    if (!Utils.isEmpty(security_out)) {
      params['security_out'] = DateTimeUtils.formatDateStr(security_out!, format: 'HH:mm:ss');
    }
    if (!Utils.isEmpty(work_in)) {
      params['work_in'] = DateTimeUtils.formatDateStr(work_in!, format: 'HH:mm:ss');
    }
    if (!Utils.isEmpty(work_out)) {
      params['work_out'] = DateTimeUtils.formatDateStr(work_out!, format: 'HH:mm:ss');
    }
    if (!Utils.isEmpty(adjustHours)) {
      params['adjust_hours'] = adjustHours ?? "";
    }
    if (!Utils.isEmpty(status)) {
      params['status'] = status ?? "";
    }

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 修改考勤员工的考勤状态
  Future<HttpResult> submitEditAppliedStatus(
    String? appliedId,
    String? status, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";
    params['status'] = status ?? "";

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 获取员工的评价信息
  Future<HttpResult<JobAppliedRemarkViewSGEntity>> fetchJobAppliedRemarkView(
    String? appliedId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";

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

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

  /// 提交员工的评价
  Future<HttpResult> submitAppliedRemark(
    String? appliedId,
    String? attitude_rate,
    String? grooming_rate,
    String? performance_rate,
    String? experience_rate,
    String? feedback, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";

    params['attitude_rate'] = (double.parse(attitude_rate ?? "5.0")).toInt().toString();
    params['grooming_rate'] = (double.parse(grooming_rate ?? "5.0")).toInt().toString();
    params['performance_rate'] = (double.parse(performance_rate ?? "5.0")).toInt().toString();
    params['experience_rate'] = (double.parse(experience_rate ?? "5.0")).toInt().toString();

    if (!Utils.isEmpty(feedback)) {
      params['feedback'] = feedback ?? "";
    }

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 获取员工的详细信息
  Future<HttpResult<StaffDetailSGEntity>> fetchStaffDetail(
    String? memberId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['member_id'] = memberId ?? "";

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

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

  /// 获取员工的做工历史列表
  Future<HttpResult<StaffJobHistorySGEntity>> fetchStaffJobHistory(
    String? memberId, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['member_id'] = memberId ?? "";
    params['cur_page'] = curPage.toString();
    params['page_size'] = "10";

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

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

  /// 获取员工的做工评价历史列表
  Future<HttpResult<StaffReviewHistorySGEntity>> fetchStaffReviewHeadView(
    String? memberId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['member_id'] = memberId ?? "";

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

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

  /// 获取员工的做工评价历史列表
  Future<HttpResult<StaffReviewHistorySGEntity>> fetchStaffReviewHistory(
    String? memberId, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['cur_page'] = curPage.toString();
    params['page_size'] = "10";
    params['member_id'] = memberId ?? "";

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

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

  /// Revise 列表选项
  Future<HttpResult<ReviseIndexSGEntity>> fetchReviseIndex({
    CancelToken? cancelToken,
  }) async {
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiReviseIndexSG,
      cancelToken: cancelToken,
    );

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

  /// Revise 列表选项
  Future<HttpResult<ReviseListSGEntity>> fetchReviseList(
    String? applied_id,
    String? status,
    String? keyword,
    String? start_date,
    String? end_date, {
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

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

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

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

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

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

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

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

  /// 根据ID获取主列表的Item数据，用于刷新Item
  Future<HttpResult<ReviseListSGEntity>> fetchReviseListByIds(
    String? reviseId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = "1";
    params["page_size"] = "9999";

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

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

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

  /// Revise 添加选项
  Future<HttpResult<AddEditReviseViewSGEntity>> fetchReviseAddIndex(
    String? applied_id, {
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["applied_id"] = applied_id ?? "";

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

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

  /// Revise 编辑选项
  Future<HttpResult<AddEditReviseViewSGEntity>> fetchReviseEditIndex(
    String? revise_id, {
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["revise_id"] = revise_id ?? "";

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

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

  /// Review Add 提交
  Future<HttpResult> submitReviseAdd(
    String? appliedId,
    String? revise_hours,
    String? revise_msg, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";

    if (!Utils.isEmpty(revise_hours)) {
      params['revise_hours'] = revise_hours ?? "";
    }

    if (!Utils.isEmpty(revise_msg)) {
      params['revise_msg'] = revise_msg ?? "";
    }

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// Review Edit 提交
  Future<HttpResult> submitReviseEdit(
    String? revise_id,
    String? revise_hours,
    String? revise_msg, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['revise_id'] = revise_id ?? "";

    if (!Utils.isEmpty(revise_hours)) {
      params['revise_hours'] = revise_hours ?? "";
    }

    if (!Utils.isEmpty(revise_msg)) {
      params['revise_msg'] = revise_msg ?? "";
    }

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// Review Recall
  Future<HttpResult> recallRevise(
    String? revise_id, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['revise_id'] = revise_id ?? "";

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// Review Delete
  Future<HttpResult> deleteRevise(
    String? revise_id, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['revise_id'] = revise_id ?? "";

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// Review Logs
  Future<HttpResult<ReviseLogSGEntity>> fetchReviseLogs(
    String? revise_id, {
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params["revise_id"] = revise_id ?? "";

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

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

  // ===================================  SG 的 Job Attendance Review 相关接口  ↓  ===================================

  /// 考勤审核列表的选项数据
  Future<HttpResult<SGAttendanceReviewOptionEntity>> fetchAttendanceReviewOption({
    CancelToken? cancelToken,
  }) async {
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiAttendanceReviewOptionSG,
      cancelToken: cancelToken,
    );

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

  /// 考勤审核列表 Table
  Future<HttpResult<SGAttendanceReviewTableEntity>> fetchAttendanceReviewTable({
    String? recordId,
    String? agencyId,
    String? startDate,
    String? endDate,
    String? outletId,
    String? keyword,
    String? status,
    required int curPage,
    CancelToken? cancelToken,
  }) async {
    Map<String, String> params = {};
    params['cur_page'] = curPage.toString();
    params['page_size'] = "10";

    if (Utils.isNotEmpty(recordId)) {
      params['record_id'] = recordId ?? "";
    }
    if (Utils.isNotEmpty(agencyId)) {
      params['agency_id'] = agencyId ?? "";
    }
    if (Utils.isNotEmpty(startDate)) {
      params['start_date'] = startDate ?? "";
    }
    if (Utils.isNotEmpty(endDate)) {
      params['end_date'] = endDate ?? "";
    }
    if (Utils.isNotEmpty(status)) {
      params['status'] = status ?? "";
    }
    if (Utils.isNotEmpty(outletId)) {
      params['outlet_id'] = outletId ?? "";
    }
    if (Utils.isNotEmpty(keyword)) {
      params['job_title'] = keyword ?? "";
    }

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

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

  /// 考勤审核的批量同意
  Future<HttpResult> approveAttendanceReviews(
    String? recordIds, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['record_ids'] = recordIds ?? "";

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 考勤审核的批量拒绝
  Future<HttpResult> rejectAttendanceReviews(
    String? recordIds,
    String? reason, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['record_ids'] = recordIds ?? "";

    if (Utils.isNotEmpty(reason)) {
      params['audit_mark'] = reason ?? "";
    }

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

    //根据返回的结果，封装原始数据为Bean/Entity对象
    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 考勤审核的状态流
  Future<HttpResult<SGAttendanceReviewWorkflowEntity>> fetchAttendanceReviewWorkFlow(
    String? appliedId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['applied_id'] = appliedId ?? "";

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

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

  /// 获取 SG Dashboard 的列表数据
  Future<HttpResult<SGDashboardEntity>> fetchDashboardList({
    String? day,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (Utils.isNotEmpty(day)) {
      params['day'] = day ?? "";
    }

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

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