import 'package:domain/entity/response/agency_detail_entity.dart';
import 'package:domain/entity/response/agency_option_entity.dart';
import 'package:domain/entity/response/agency_table_entity.dart';
import 'package:domain/entity/response/contract_detail_entity.dart';
import 'package:domain/entity/response/contract_option_entity.dart';
import 'package:domain/entity/response/contract_position_add_option_entity.dart';
import 'package:domain/entity/response/contract_position_option_entity.dart';
import 'package:domain/entity/response/contract_position_rate_detail_entity.dart';
import 'package:domain/entity/response/contract_position_rate_specific_option_entity.dart';
import 'package:domain/entity/response/contract_position_rate_table_entity.dart';
import 'package:domain/entity/response/contract_position_table_entity.dart';
import 'package:domain/entity/response/contract_table_entity.dart';
import 'package:domain/entity/response/position_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';

/// SG的中介相关数据仓库
class SGAgencyRepository extends GetxService {
  HttpProvider httpProvider;

  SGAgencyRepository({required this.httpProvider});

  /// 获取中介列表选项
  Future<HttpResult<AgencyOptionEntity>> fetchAgencyOption({
    CancelToken? cancelToken,
  }) async {
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiAgencyOption,
    );

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = AgencyOptionEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<AgencyOptionEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介列表Table
  Future<HttpResult<AgencyTableEntity>> fetchAgencyTable({
    required int curPage,
    String? keyword,
    String? status,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

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

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = AgencyTableEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<AgencyTableEntity>(data: data);
    }
    return result.convert();
  }

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

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

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

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

  /// 删除中介
  Future<HttpResult> deleteAgencySubmit(
    String? pivotId, {
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};

    params['pivot_id'] = pivotId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 添加中介
  Future<HttpResult> addAgencySubmit({
    required String? agencyName,
    required String? acraNo,
    String? contactPerson,
    String? address,
    String? contactNo,
    String? contactEmail,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['agency_name'] = agencyName ?? "";
    params['acra_no'] = acraNo ?? "";
    if (!Utils.isEmpty(contactPerson)) {
      params["contact_person"] = contactPerson!;
    }
    if (!Utils.isEmpty(address)) {
      params["address"] = address!;
    }
    if (!Utils.isEmpty(contactNo)) {
      params["contact_no"] = contactNo!;
    }
    if (!Utils.isEmpty(contactEmail)) {
      params["contact_email"] = contactEmail!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 编辑中介
  Future<HttpResult> editAgencySubmit({
    required String? pivotId,
    required String? agencyName,
    required String? acraNo,
    String? contactPerson,
    String? address,
    String? contactNo,
    String? contactEmail,
    String? status,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['pivot_id'] = pivotId ?? "";
    params['agency_name'] = agencyName ?? "";
    params['acra_no'] = acraNo ?? "";
    if (!Utils.isEmpty(contactPerson)) {
      params["contact_person"] = contactPerson!;
    }
    if (!Utils.isEmpty(address)) {
      params["address"] = address!;
    }
    if (!Utils.isEmpty(contactNo)) {
      params["contact_no"] = contactNo!;
    }
    if (!Utils.isEmpty(contactEmail)) {
      params["contact_email"] = contactEmail!;
    }
    if (!Utils.isEmpty(status)) {
      params["status"] = status!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 获取中介的编辑详情
  Future<HttpResult<AgencyDetailEntity>> fetchAgencyEditDetail({
    required String? pivotId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    if (!Utils.isEmpty(pivotId)) {
      params["pivot_id"] = pivotId!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = AgencyDetailEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<AgencyDetailEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介职位的列表
  Future<HttpResult<PositionTableEntity>> fetchPositionTable({
    required int curPage,
    String? keyword,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

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

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = PositionTableEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<PositionTableEntity>(data: data);
    }
    return result.convert();
  }

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

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

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

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

  /// 添加职位
  Future<HttpResult> addPositionSubmit({
    required String? name,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['name'] = name ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 编辑职位
  Future<HttpResult> editPositionSubmit({
    required String? positionId,
    required String? name,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['position_id'] = positionId ?? "";
    params['name'] = name ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 删除职位
  Future<HttpResult> deletePositionSubmit({
    required String? positionId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['position_id'] = positionId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 获取中介合同列表选项
  Future<HttpResult<ContractOptionEntity>> fetchContractOption({
    CancelToken? cancelToken,
  }) async {
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiContractOption,
    );

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractOptionEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractOptionEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介合同列表Table
  Future<HttpResult<ContractTableEntity>> fetchContractTable({
    required int curPage,
    String? agencyId,
    String? status,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    if (Utils.isNotEmpty(agencyId)) {
      params["agency_id"] = agencyId!;
    }
    if (Utils.isNotEmpty(status)) {
      params["status"] = status!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractTableEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractTableEntity>(data: data);
    }
    return result.convert();
  }

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

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

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

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

  /// 获取中介的合同添加详情
  Future<HttpResult<ContractDetailEntity>> fetchContractAddOption({
    CancelToken? cancelToken,
  }) async {
    final result = await httpProvider.requestNetResult(
      ApiConstants.apiContractAddOption,
      isShowLoadingDialog: true,
      cancelToken: cancelToken,
    );

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractDetailEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractDetailEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介的合同编辑详情
  Future<HttpResult<ContractDetailEntity>> fetchContractEditDetail({
    required String? contractId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["contract_id"] = contractId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractDetailEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractDetailEntity>(data: data);
    }
    return result.convert();
  }

  /// 添加合同
  Future<HttpResult> addContractSubmit({
    required String? agencyId,
    required String? startDate,
    required String? endDate,
    List<String>? paths,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['agency_id'] = agencyId ?? "";
    params['start_date'] = startDate ?? "";
    params['end_date'] = endDate ?? "";

    //文件
    Map<String, String> fileParams = {};
    if (paths != null && paths.isNotEmpty) {
      fileParams['file'] = paths[0];
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 编辑合同
  Future<HttpResult> editContractSubmit({
    required String? contractId,
    required String? agencyId,
    required String? startDate,
    required String? endDate,
    List<String>? paths,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['contract_id'] = contractId ?? "";
    params['agency_id'] = agencyId ?? "";
    params['start_date'] = startDate ?? "";
    params['end_date'] = endDate ?? "";

    //文件
    Map<String, String> fileParams = {};
    if (paths != null && paths.isNotEmpty) {
      fileParams['file'] = paths[0];
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// Renew合同
  Future<HttpResult> renewContractSubmit({
    required String? contractId,
    required String? agencyId,
    required String? startDate,
    required String? endDate,
    List<String>? paths,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['contract_id'] = contractId ?? "";
    params['agency_id'] = agencyId ?? "";
    params['start_date'] = startDate ?? "";
    params['end_date'] = endDate ?? "";

    //文件
    Map<String, String> fileParams = {};
    if (paths != null && paths.isNotEmpty) {
      fileParams['file'] = paths[0];
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 合同关联职位 Option
  Future<HttpResult<ContractPositionOptionEntity>> fetchContractPositionOption({
    required String? contractId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["contract_id"] = contractId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractPositionOptionEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractPositionOptionEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介合同列表Table
  Future<HttpResult<ContractPositionTableEntity>> fetchContractPositionTable({
    required int curPage,
    required String? contractId,
    String? positionId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "10";

    params["contract_id"] = contractId ?? "";

    if (Utils.isNotEmpty(positionId)) {
      params["position_id"] = positionId!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractPositionTableEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractPositionTableEntity>(data: data);
    }
    return result.convert();
  }

  /// 合同关联职位 添加Option
  Future<HttpResult<ContractPositionAddOptionEntity>> fetchContractPositionAddOption({
    required String? contractId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["contract_id"] = contractId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractPositionAddOptionEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractPositionAddOptionEntity>(data: data);
    }
    return result.convert();
  }

  /// 合同关联职位 添加Submit
  Future<HttpResult> addContractPositionSubmit({
    required String? contractId,
    required String? positionId,
    String? type_1,
    String? type_2,
    String? type_3,
    String? type_7,
    String? type_8,
    String? type_9,
    String? type_10,
    String? type_11,
    String? type_12,
    String? type_13,
    String? type_20,
    String? type_21,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['contract_id'] = contractId ?? "";
    params['position_id'] = positionId ?? "";

    if (Utils.isNotEmpty(type_1)) {
      params['type_1'] = type_1!;
    }
    if (Utils.isNotEmpty(type_2)) {
      params['type_2'] = type_2!;
    }
    if (Utils.isNotEmpty(type_3)) {
      params['type_3'] = type_3!;
    }
    if (Utils.isNotEmpty(type_7)) {
      params['type_7'] = type_7!;
    }
    if (Utils.isNotEmpty(type_8)) {
      params['type_8'] = type_8!;
    }
    if (Utils.isNotEmpty(type_9)) {
      params['type_9'] = type_9!;
    }
    if (Utils.isNotEmpty(type_10)) {
      params['type_10'] = type_10!;
    }
    if (Utils.isNotEmpty(type_11)) {
      params['type_11'] = type_11!;
    }
    if (Utils.isNotEmpty(type_12)) {
      params['type_12'] = type_12!;
    }
    if (Utils.isNotEmpty(type_13)) {
      params['type_13'] = type_13!;
    }
    if (Utils.isNotEmpty(type_20)) {
      params['type_20'] = type_20!;
    }
    if (Utils.isNotEmpty(type_21)) {
      params['type_21'] = type_21!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 合同关联职位 编辑详情
  Future<HttpResult<ContractPositionRateDetailEntity>> fetchContractPositionRateDetail({
    required String? contractId,
    required String? positionId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["contract_id"] = contractId ?? "";
    params["position_id"] = positionId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractPositionRateDetailEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractPositionRateDetailEntity>(data: data);
    }
    return result.convert();
  }

  /// 合同关联职位 费率编辑的Submit
  Future<HttpResult> editContractPositionRateSubmit({
    required String? contractId,
    required String? positionId,
    String? type_1,
    String? type_2,
    String? type_3,
    String? type_7,
    String? type_8,
    String? type_9,
    String? type_10,
    String? type_11,
    String? type_12,
    String? type_13,
    String? type_20,
    String? type_21,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['contract_id'] = contractId ?? "";
    params['position_id'] = positionId ?? "";

    if (Utils.isNotEmpty(type_1)) {
      params['type_1'] = type_1!;
    }
    if (Utils.isNotEmpty(type_2)) {
      params['type_2'] = type_2!;
    }
    if (Utils.isNotEmpty(type_3)) {
      params['type_3'] = type_3!;
    }
    if (Utils.isNotEmpty(type_7)) {
      params['type_7'] = type_7!;
    }
    if (Utils.isNotEmpty(type_8)) {
      params['type_8'] = type_8!;
    }
    if (Utils.isNotEmpty(type_9)) {
      params['type_9'] = type_9!;
    }
    if (Utils.isNotEmpty(type_10)) {
      params['type_10'] = type_10!;
    }
    if (Utils.isNotEmpty(type_11)) {
      params['type_11'] = type_11!;
    }
    if (Utils.isNotEmpty(type_12)) {
      params['type_12'] = type_12!;
    }
    if (Utils.isNotEmpty(type_13)) {
      params['type_13'] = type_13!;
    }
    if (Utils.isNotEmpty(type_20)) {
      params['type_20'] = type_20!;
    }
    if (Utils.isNotEmpty(type_21)) {
      params['type_21'] = type_21!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 获取中介合同的时薪列表Table
  Future<HttpResult<ContractPositionRateTableEntity>> fetchContractPositionRateTable({
    required int curPage,
    required String? contractId,
    required String? positionId,
    String? rateId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["cur_page"] = curPage.toString();
    params["page_size"] = "20";
    params["contract_id"] = contractId ?? "";
    params["position_id"] = positionId ?? "";

    if (Utils.isNotEmpty(rateId)) {
      params["rate_id"] = rateId!;
    }

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractPositionRateTableEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractPositionRateTableEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介合同的时薪，指定日期Option
  Future<HttpResult<ContractPositionRateSpecificOptionEntity>> fetchContractPositionRateSpecificOption({
    required String? contractId,
    required String? positionId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params["contract_id"] = contractId ?? "";
    params["position_id"] = positionId ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      final json = result.getDataJson();
      var data = ContractPositionRateSpecificOptionEntity.fromJson(json!);
      //重新赋值data或list
      return result.convert<ContractPositionRateSpecificOptionEntity>(data: data);
    }
    return result.convert();
  }

  /// 获取中介合同的时薪，指定日期添加
  Future<HttpResult> addContractPositionRateSpecificSubmit({
    required String? contractId,
    required String? positionId,
    required String? day,
    required String? amount,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['contract_id'] = contractId ?? "";
    params['position_id'] = positionId ?? "";
    params['special_day'] = day ?? "";
    params['amount'] = amount ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 中介合同时薪 修改金额
  Future<HttpResult> editContractPositionRateAmountEdit({
    required String? rateId,
    required String? amount,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['rate_id'] = rateId ?? "";;
    params['amount'] = amount ?? "";

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

  /// 中介合同时薪 删除记录
  Future<HttpResult> deleteContractPositionRate({
    required String? rateId,
    CancelToken? cancelToken,
  }) async {
    //参数
    Map<String, String> params = {};
    params['rate_id'] = rateId ?? "";;

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

    if (result.isSuccess) {
      //重新赋值data或list
      return result.convert();
    }
    return result.convert();
  }

}
