/**
 * Project YooLearn
 * File skills.actions
 * Path app/redux/skills
 * Created by BRICE ZELE
 * Date: 13/09/2021
 */
import InsuranceActions from './insurance.type';
import {
    autorisationCareRequestUrl,
    buyInsuranceUrl,
    checkInsuranceCoverageAmountUrl,
    consultationUrl,
    createConsultationUrl,
    exclusionUrl,
    executionPrescriptionUrl,
    getAmountConsultationUrl,
    getDrugAndDevicesUrl,
    getInsuranceListUrl,
    getInsurancePrimeAmountUrl,
    getNetworkActsUrl,
    getProviderClassUrl,
    getUserByIdQRCodeUrl,
    getUserByNameOrNumberUrl,
    invoiceUrl,
    invoiceUserUrl,
    subscribeInsuranceUrl,
    uploadInsuranceImagetUrl
} from "../../webservice/IlinkConstants";
import {ApiAction} from "../reducers";

export const fetchGetListInsurancePending = () => ({
    type: InsuranceActions.GET_INSURANCE_LIST_PENDING,
});

export const fetchGetListInsuranceReset = () => ({
    type: InsuranceActions.GET_INSURANCE_LIST_RESET,
});

export const fetchGetListInsuranceSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_INSURANCE_LIST_SUCCESS,
    payload: authkey,
});

export const fetchGetListInsuranceError = (error: any) => ({
    type: InsuranceActions.GET_INSURANCE_LIST_ERROR,
    payload: error,
});

export const fetchGetListInsurance = (idCountry, otherParam = '') => {
    return ApiAction({
        url: `${getInsuranceListUrl}/networks?country_id=${idCountry}${otherParam}`,
        method: 'GET',
        onLoading: fetchGetListInsurancePending,
        onSuccess: fetchGetListInsuranceSuccess,
        onError: fetchGetListInsuranceError,
    });
};

export const fetchGetListInsuranceWithBeneficiaries = (param = '') => {
    return ApiAction({
        url: `${getInsuranceListUrl}${param}`,
        method: 'GET',
        onLoading: fetchGetListInsurancePending,
        onSuccess: fetchGetListInsuranceSuccess,
        onError: fetchGetListInsuranceError,
    });
};

/************************************************************/
export const fetchSubscribeInsurancePending = () => ({
    type: InsuranceActions.SUBSCRIBE_INSURANCE_PENDING,
});

export const fetchSubscribeInsuranceReset = () => ({
    type: InsuranceActions.SUBSCRIBE_INSURANCE_RESET,
});

export const fetchSubscribeInsuranceSuccess = (authkey: any) => ({
    type: InsuranceActions.SUBSCRIBE_INSURANCE_SUCCESS,
    payload: authkey,
});

export const fetchSubscribeInsuranceError = (error: any) => ({
    type: InsuranceActions.SUBSCRIBE_INSURANCE_ERROR,
    payload: error,
});

export const fetchSubscribeInsurance = (data) => {
    return ApiAction({
        url: subscribeInsuranceUrl,
        data,
        method: 'POST',
        onLoading: fetchSubscribeInsurancePending,
        onSuccess: fetchSubscribeInsuranceSuccess,
        onError: fetchSubscribeInsuranceError,
    });
};

/************************************************************/
export const fetchGetInsurancePrimeAmountPending = () => ({
    type: InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_PENDING,
});

export const fetchGetInsurancePrimeAmountReset = () => ({
    type: InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_RESET,
});

export const fetchGetInsurancePrimeAmountSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_SUCCESS,
    payload: authkey,
});

export const fetchGetInsurancePrimeAmountError = (error: any) => ({
    type: InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_ERROR,
    payload: error,
});

export const fetchGetInsurancePrimeAmount = (data) => {
    return ApiAction({
        url: getInsurancePrimeAmountUrl,
        data,
        method: 'POST',
        onLoading: fetchGetInsurancePrimeAmountPending,
        onSuccess: fetchGetInsurancePrimeAmountSuccess,
        onError: fetchGetInsurancePrimeAmountError,
    });
};

/************************************************************/
export const fetchUploadInsurancePending = () => ({
    type: InsuranceActions.UPLOAD_INSURANCE_IMAGES_PENDING,
});

export const fetchUploadInsuranceReset = () => ({
    type: InsuranceActions.UPLOAD_INSURANCE_IMAGES_RESET,
});

export const fetchUploadInsuranceSuccess = (authkey: any) => ({
    type: InsuranceActions.UPLOAD_INSURANCE_IMAGES_SUCCESS,
    payload: authkey,
});

export const fetchUploadInsuranceError = (error: any) => ({
    type: InsuranceActions.UPLOAD_INSURANCE_IMAGES_ERROR,
    payload: error,
});

export const fetchUploadInsurance = (data) => {
    return ApiAction({
        url: uploadInsuranceImagetUrl,
        data,
        accessToken: 'gZ7KibrSvFNLxrGz49usnRiKBZ4OlX99',
        method: 'POST',
        onLoading: fetchUploadInsurancePending,
        onSuccess: fetchUploadInsuranceSuccess,
        onError: fetchUploadInsuranceError,
    });
};

/************************************************************/
export const fetchGetSubscriptionListPending = () => ({
    type: InsuranceActions.GET_SUBSCRIPTION_LIST_PENDING,
});

export const fetchGetSubscriptionListReset = () => ({
    type: InsuranceActions.GET_SUBSCRIPTION_LIST_RESET,
});

export const fetchGetSubscriptionListSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_SUBSCRIPTION_LIST_SUCCESS,
    payload: authkey,
});

export const fetchGetSubscriptionListError = (error: any) => ({
    type: InsuranceActions.GET_SUBSCRIPTION_LIST_ERROR,
    payload: error,
});

export const fetchGetSubscriptionList = (idUser, type, includeSubscription = true) => {
    return ApiAction({
        url: includeSubscription ? `${buyInsuranceUrl}?user_id=${idUser}&state=${type}` : `${getInsuranceListUrl}?user_id=${idUser}&type=${type}`,
        method: 'GET',
        onLoading: fetchGetSubscriptionListPending,
        onSuccess: fetchGetSubscriptionListSuccess,
        onError: fetchGetSubscriptionListError,
    });
};

/************************************************************/
export const fetchActivePaySubscriptionPending = () => ({
    type: InsuranceActions.ACTIVATE_PAY_SUBSCRIPTION_PENDING,
});

export const fetchActivePaySubscriptionReset = () => ({
    type: InsuranceActions.ACTIVATE_PAY_SUBSCRIPTION_RESET,
});

export const fetchActivePaySubscriptionSuccess = (authkey: any) => ({
    type: InsuranceActions.ACTIVATE_PAY_SUBSCRIPTION_SUCCESS,
    payload: authkey,
});

export const fetchActivePaySubscriptionError = (error: any) => ({
    type: InsuranceActions.ACTIVATE_PAY_SUBSCRIPTION_ERROR,
    payload: error,
});

export const fetchActivePaySubscription = (id, data) => {
    console.debug("execute la reque stp...")
    return ApiAction({
        url: `${buyInsuranceUrl}/${id}/pay`,
        data,
        method: 'PUT',
        onLoading: fetchActivePaySubscriptionPending,
        onSuccess: fetchActivePaySubscriptionSuccess,
        onError: fetchActivePaySubscriptionError,
    });
};

/************************************************************/
export const fetchStopSubscriptionPending = () => ({
    type: InsuranceActions.STOP_SUBSCRIPTION_PENDING,
});

export const fetchStopSubscriptionReset = () => ({
    type: InsuranceActions.STOP_SUBSCRIPTION_RESET,
});

export const fetchStopSubscriptionSuccess = (authkey: any) => ({
    type: InsuranceActions.STOP_SUBSCRIPTION_SUCCESS,
    payload: authkey,
});

export const fetchStopSubscriptionError = (error: any) => ({
    type: InsuranceActions.STOP_SUBSCRIPTION_ERROR,
    payload: error,
});

export const fetchStopSubscription = (id, data) => {
    return ApiAction({
        url: `${getInsuranceListUrl}/${id}/stop`,
        data,
        method: 'PUT',
        onLoading: fetchStopSubscriptionPending,
        onSuccess: fetchStopSubscriptionSuccess,
        onError: fetchStopSubscriptionError,
    });
};

export const fetchRenewSubscription = (id, data) => {
    return ApiAction({
        url: `${getInsuranceListUrl}/${id}/renew`,
        data,
        method: 'PUT',
        onLoading: fetchStopSubscriptionPending,
        onSuccess: fetchStopSubscriptionSuccess,
        onError: fetchStopSubscriptionError,
    });
};

/************************************************************/
export const fetchAddBeneficiaryToSubscriptionPending = () => ({
    type: InsuranceActions.ADD_BENEFICIARY_TO_SUBSCRIPTION_PENDING,
});

export const fetchAddBeneficiaryToSubscriptionReset = () => ({
    type: InsuranceActions.ADD_BENEFICIARY_TO_SUBSCRIPTION_RESET,
});

export const fetchAddBeneficiaryToSubscriptionSuccess = (authkey: any) => ({
    type: InsuranceActions.ADD_BENEFICIARY_TO_SUBSCRIPTION_SUCCESS,
    payload: authkey,
});

export const fetchAddBeneficiaryToSubscriptionError = (error: any) => ({
    type: InsuranceActions.ADD_BENEFICIARY_TO_SUBSCRIPTION_ERROR,
    payload: error,
});

export const fetchAddBeneficiaryToSubscription = (id, data) => {
    return ApiAction({
        url: `${getInsuranceListUrl}/${id}/add-beneficiaries`,
        data,
        method: 'PUT',
        onLoading: fetchAddBeneficiaryToSubscriptionPending,
        onSuccess: fetchAddBeneficiaryToSubscriptionSuccess,
        onError: fetchAddBeneficiaryToSubscriptionError,
    });
};

/************************************************************/
export const fetchGetUserByIdQRCodePending = () => ({
    type: InsuranceActions.GET_USER_BY_ID_QR_CODE_PENDING,
});

export const fetchGetUserByIdQRCodeReset = () => ({
    type: InsuranceActions.GET_USER_BY_ID_QR_CODE_RESET,
});

export const fetchGetUserByIdQRCodeSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_USER_BY_ID_QR_CODE_SUCCESS,
    payload: authkey,
});

export const fetchGetUserByIdQRCodeError = (error: any) => ({
    type: InsuranceActions.GET_USER_BY_ID_QR_CODE_ERROR,
    payload: error,
});

export const fetchGetUserByIdQRCode = (id) => {
    return ApiAction({
        url: `${getUserByIdQRCodeUrl}?${id}`,
        method: 'GET',
        onLoading: fetchGetUserByIdQRCodePending,
        onSuccess: fetchGetUserByIdQRCodeSuccess,
        onError: fetchGetUserByIdQRCodeError,
    });
};

/************************************************************/
export const fetchGetUserByNameOrNumberPending = () => ({
    type: InsuranceActions.GET_USER_BY_NAME_OR_NUMBER_PENDING,
});

export const fetchGetUserByNameOrNumberReset = () => ({
    type: InsuranceActions.GET_USER_BY_NAME_OR_NUMBER_RESET,
});

export const fetchGetUserByNameOrNumberSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_USER_BY_NAME_OR_NUMBER_SUCCESS,
    payload: authkey,
});

export const fetchGetUserByNameOrNumberError = (error: any) => ({
    type: InsuranceActions.GET_USER_BY_NAME_OR_NUMBER_ERROR,
    payload: error,
});

export const fetchGetUserByNameOrNumber = (network_id, id) => {
    return ApiAction({
        url: `${getUserByNameOrNumberUrl}?network_id=${network_id}${id}`,
        method: 'GET',
        onLoading: fetchGetUserByNameOrNumberPending,
        onSuccess: fetchGetUserByNameOrNumberSuccess,
        onError: fetchGetUserByNameOrNumberError,
    });
};

/************************************************************/
export const fetchGetDrugAppareilPending = () => ({
    type: InsuranceActions.GET_DRUG_APPAREIL_PENDING,
});

export const fetchGetDrugAppareilReset = () => ({
    type: InsuranceActions.GET_DRUG_APPAREIL_RESET,
});

export const fetchGetDrugAppareilSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_DRUG_APPAREIL_SUCCESS,
    payload: authkey,
});

export const fetchGetDrugAppareilError = (error: any) => ({
    type: InsuranceActions.GET_DRUG_APPAREIL_ERROR,
    payload: error,
});

export const fetchGetDrugAppareil = (network_id, name) => {
    return ApiAction({
        url: `${getDrugAndDevicesUrl}?network_id=${network_id}&name=${name}`,
        method: 'GET',
        onLoading: fetchGetDrugAppareilPending,
        onSuccess: fetchGetDrugAppareilSuccess,
        onError: fetchGetDrugAppareilError,
    });
};

/************************************************************/
export const fetchAddDrugPending = () => ({
    type: InsuranceActions.ADD_DRUG_PENDING,
});

export const fetchAddDrugReset = () => ({
    type: InsuranceActions.ADD_DRUG_RESET,
});

export const fetchAddDrugSuccess = (authkey: any) => ({
    type: InsuranceActions.ADD_DRUG_SUCCESS,
    payload: authkey,
});

export const fetchAddDrugError = (error: any) => ({
    type: InsuranceActions.ADD_DRUG_ERROR,
    payload: error,
});

export const fetchAddDrug = (data) => {
    return ApiAction({
        url: `${getDrugAndDevicesUrl}`,
        method: 'POST',
        data,
        onLoading: fetchAddDrugPending,
        onSuccess: fetchAddDrugSuccess,
        onError: fetchAddDrugError,
    });
};

/************************************************************/
export const fetchGetProviderClassPending = () => ({
    type: InsuranceActions.GET_PROVIDER_CLASS_PENDING,
});

export const fetchGetProviderClassReset = () => ({
    type: InsuranceActions.GET_PROVIDER_CLASS_RESET,
});

export const fetchGetProviderClassSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_PROVIDER_CLASS_SUCCESS,
    payload: authkey,
});

export const fetchGetProviderClassError = (error: any) => ({
    type: InsuranceActions.GET_PROVIDER_CLASS_ERROR,
    payload: error,
});

export const fetchGetProviderClass = (network_id) => {
    return ApiAction({
        url: `${getProviderClassUrl}?network_id=${network_id}`,
        method: 'GET',
        onLoading: fetchGetProviderClassPending,
        onSuccess: fetchGetProviderClassSuccess,
        onError: fetchGetProviderClassError,
    });
};

/************************************************************/
export const fetchGetNetworkActsPending = () => ({
    type: InsuranceActions.GET_NETWORK_ACT_PENDING,
});

export const fetchGetNetworkActsReset = () => ({
    type: InsuranceActions.GET_NETWORK_ACT_RESET,
});

export const fetchGetNetworkActsSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_NETWORK_ACT_SUCCESS,
    payload: authkey,
});

export const fetchGetNetworkActsError = (error: any) => ({
    type: InsuranceActions.GET_NETWORK_ACT_ERROR,
    payload: error,
});

export const fetchGetNetworkActs = (network_id, code = '', otherParam = '') => {
    return ApiAction({
        url: `${getNetworkActsUrl}?network_id=${network_id}&code=${code}${otherParam}`,
        method: 'GET',
        onLoading: fetchGetNetworkActsPending,
        onSuccess: fetchGetNetworkActsSuccess,
        onError: fetchGetNetworkActsError,
    });
};

/************************************************************/
export const fetchCreateConsultationPending = () => ({
    type: InsuranceActions.CREATE_CONSULTATION_PENDING,
});

export const fetchCreateConsultationReset = () => ({
    type: InsuranceActions.CREATE_CONSULTATION_RESET,
});

export const fetchCreateConsultationSuccess = (authkey: any) => ({
    type: InsuranceActions.CREATE_CONSULTATION_SUCCESS,
    payload: authkey,
});

export const fetchCreateConsultationError = (error: any) => ({
    type: InsuranceActions.CREATE_CONSULTATION_ERROR,
    payload: error,
});

export const fetchCreateConsultation = (data) => {
    return ApiAction({
        url: `${createConsultationUrl}`,
        method: 'POST',
        data,
        onLoading: fetchCreateConsultationPending,
        onSuccess: fetchCreateConsultationSuccess,
        onError: fetchCreateConsultationError,
    });
};

/************************************************************/
export const fetchGetAmountConsultationPending = () => ({
    type: InsuranceActions.GET_AMOUNT_CONSULTATION_PENDING,
});

export const fetchGetAmountConsultationReset = () => ({
    type: InsuranceActions.GET_AMOUNT_CONSULTATION_RESET,
});

export const fetchGetAmountConsultationSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_AMOUNT_CONSULTATION_SUCCESS,
    payload: authkey,
});

export const fetchGetAmountConsultationError = (error: any) => ({
    type: InsuranceActions.GET_AMOUNT_CONSULTATION_ERROR,
    payload: error,
});

export const fetchGetAmountConsultation = (data) => {
    return ApiAction({
        url: `${getAmountConsultationUrl}`,
        method: 'POST',
        data,
        onLoading: fetchGetAmountConsultationPending,
        onSuccess: fetchGetAmountConsultationSuccess,
        onError: fetchGetAmountConsultationError,
    });
};

/************************************************************/
export const fetchGetConsultationPending = () => ({
    type: InsuranceActions.GET_USER_CONSULTATION_PENDING,
});

export const fetchGetConsultationReset = () => ({
    type: InsuranceActions.GET_USER_CONSULTATION_RESET,
});

export const fetchGetConsultationSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_USER_CONSULTATION_SUCCESS,
    payload: authkey,
});

export const fetchGetConsultationError = (error: any) => ({
    type: InsuranceActions.GET_USER_CONSULTATION_ERROR,
    payload: error,
});

export const fetchGetConsultation = (user_id, state = 'UNTREATED', typeParam = 'CONSULTATION', otherParam = '') => {
    console.log("user_id", user_id);
    return ApiAction({
        url: `${consultationUrl}?state=${state}&type=${typeParam}${user_id !== '' ? '&user_id=' + user_id : ''}${otherParam}`,
        method: 'GET',
        onLoading: fetchGetConsultationPending,
        onSuccess: fetchGetConsultationSuccess,
        onError: fetchGetConsultationError,
    });
};

export const fetchGetInvoiceHistory = (otherParam, isUser = false) => {
    return ApiAction({
        url: isUser ? `${invoiceUserUrl}${otherParam}` : `${invoiceUrl}${otherParam}`,
        method: 'GET',
        onLoading: fetchGetConsultationPending,
        onSuccess: fetchGetConsultationSuccess,
        onError: fetchGetConsultationError,
    });
};

export const fetchGetSubscription = (user_id, typeParam = 'ALL', otherParam = '') => {
    console.log("user_id", user_id);
    return ApiAction({
        url: `${subscribeInsuranceUrl}?user_id=${user_id}&type=${typeParam}${otherParam}`,
        method: 'GET',
        onLoading: fetchGetConsultationPending,
        onSuccess: fetchGetConsultationSuccess,
        onError: fetchGetConsultationError,
    });
};

/************************************************************/
export const fetchAcceptRejectConsultationPending = () => ({
    type: InsuranceActions.ACCEPT_REJECT_CONSULTATION_PENDING,
});

export const fetchAcceptRejectConsultationReset = () => ({
    type: InsuranceActions.ACCEPT_REJECT_CONSULTATION_RESET,
});

export const fetchAcceptRejectConsultationSuccess = (authkey: any) => ({
    type: InsuranceActions.ACCEPT_REJECT_CONSULTATION_SUCCESS,
    payload: authkey,
});

export const fetchAcceptRejectConsultationError = (error: any) => ({
    type: InsuranceActions.ACCEPT_REJECT_CONSULTATION_ERROR,
    payload: error,
});

export const fetchAcceptRejectConsultation = (data) => {
    return ApiAction({
        url: `${consultationUrl}`,
        method: 'PUT',
        data,
        onLoading: fetchAcceptRejectConsultationPending,
        onSuccess: fetchAcceptRejectConsultationSuccess,
        onError: fetchAcceptRejectConsultationError,
    });
};

/************************************************************/
export const fetchExecutionPrescriptionPending = () => ({
    type: InsuranceActions.EXECUTION_PRESCRIPTION_PENDING,
});

export const fetchExecutionPrescriptionReset = () => ({
    type: InsuranceActions.EXECUTION_PRESCRIPTION_RESET,
});

export const fetchExecutionPrescriptionSuccess = (authkey: any) => ({
    type: InsuranceActions.EXECUTION_PRESCRIPTION_SUCCESS,
    payload: authkey,
});

export const fetchExecutionPrescriptionError = (error: any) => ({
    type: InsuranceActions.EXECUTION_PRESCRIPTION_ERROR,
    payload: error,
});

export const fetchExecutionPrescription = (data) => {
    return ApiAction({
        url: `${executionPrescriptionUrl}`,
        method: 'POST',
        data,
        onLoading: fetchExecutionPrescriptionPending,
        onSuccess: fetchExecutionPrescriptionSuccess,
        onError: fetchExecutionPrescriptionError,
    });
};

/************************************************************/
export const fetchModifyPrescriptionPending = () => ({
    type: InsuranceActions.MODIFY_PRESCRIPTION_PENDING,
});

export const fetchModifyPrescriptionReset = () => ({
    type: InsuranceActions.MODIFY_PRESCRIPTION_RESET,
});

export const fetchModifyPrescriptionSuccess = (authkey: any) => ({
    type: InsuranceActions.MODIFY_PRESCRIPTION_SUCCESS,
    payload: authkey,
});

export const fetchModifyPrescriptionError = (error: any) => ({
    type: InsuranceActions.MODIFY_PRESCRIPTION_ERROR,
    payload: error,
});

export const fetchModifyPrescription = (id, data) => {
    return ApiAction({
        url: `${consultationUrl}/${id}`,
        method: 'PUT',
        data,
        onLoading: fetchModifyPrescriptionPending,
        onSuccess: fetchModifyPrescriptionSuccess,
        onError: fetchModifyPrescriptionError,
    });
};

/************************************************************/
export const fetchDemaneAutorisationSoinPending = () => ({
    type: InsuranceActions.DEMAND_AUTORISATION_PENDING,
});

export const fetchDemaneAutorisationSoinReset = () => ({
    type: InsuranceActions.DEMAND_AUTORISATION_RESET,
});

export const fetchDemaneAutorisationSoinSuccess = (authkey: any) => ({
    type: InsuranceActions.DEMAND_AUTORISATION_SUCCESS,
    payload: authkey,
});

export const fetchDemaneAutorisationSoinError = (error: any) => ({
    type: InsuranceActions.DEMAND_AUTORISATION_ERROR,
    payload: error,
});

export const fetchDemaneAutorisationSoin = (data) => {
    return ApiAction({
        url: `${autorisationCareRequestUrl}`,
        method: 'POST',
        data,
        onLoading: fetchDemaneAutorisationSoinPending,
        onSuccess: fetchDemaneAutorisationSoinSuccess,
        onError: fetchDemaneAutorisationSoinError,
    });
};

export const fetchGetDemandeAutorisationSoin = (param = '') => {
    return ApiAction({
        url: `${autorisationCareRequestUrl}${param}`,
        method: 'GET',
        onLoading: fetchGetConsultationPending,
        onSuccess: fetchGetConsultationSuccess,
        onError: fetchGetConsultationError
    });
};

/************************************************************/
export const fetchDeleteBeneficiaryPending = () => ({
    type: InsuranceActions.DELETE_BENEFICIARY_PENDING,
});

export const fetchDeleteBeneficiaryReset = () => ({
    type: InsuranceActions.DELETE_BENEFICIARY_RESET,
});

export const fetchDeleteBeneficiarySuccess = (authkey: any) => ({
    type: InsuranceActions.DELETE_BENEFICIARY_SUCCESS,
    payload: authkey,
});

export const fetchDeleteBeneficiaryError = (error: any) => ({
    type: InsuranceActions.DELETE_BENEFICIARY_ERROR,
    payload: error,
});

export const fetchDeleteBeneficiary = (id, data) => {
    return ApiAction({
        url: `${getInsuranceListUrl}/${id}/delete-beneficiaries`,
        method: 'PUT',
        data,
        onLoading: fetchDeleteBeneficiaryPending,
        onSuccess: fetchDeleteBeneficiarySuccess,
        onError: fetchDeleteBeneficiaryError,
    });
};

/************************************************************/
export const fetchCheckInsuranceCoverageAmountPending = () => ({
    type: InsuranceActions.CHECK_HEALTH_CARE_SHEET_PENDING,
});

export const fetchCheckInsuranceCoverageAmountReset = () => ({
    type: InsuranceActions.CHECK_HEALTH_CARE_SHEET_RESET,
});

export const fetchCheckInsuranceCoverageAmountSuccess = (authkey: any) => ({
    type: InsuranceActions.CHECK_HEALTH_CARE_SHEET_SUCCESS,
    payload: authkey,
});

export const fetchCheckInsuranceCoverageAmountError = (error: any) => ({
    type: InsuranceActions.CHECK_HEALTH_CARE_SHEET_ERROR,
    payload: error,
});

export const fetchCheckInsuranceCoverageAmount = (data) => {
    return ApiAction({
        url: checkInsuranceCoverageAmountUrl,
        method: 'POST',
        data,
        onLoading: fetchCheckInsuranceCoverageAmountPending,
        onSuccess: fetchCheckInsuranceCoverageAmountSuccess,
        onError: fetchCheckInsuranceCoverageAmountError,
    });
};

/************************************************************/
export const fetchGetExclusionPending = () => ({
    type: InsuranceActions.GET_EXCLUSION_PENDING,
});

export const fetchGetExclusionReset = () => ({
    type: InsuranceActions.GET_EXCLUSION_RESET,
});

export const fetchGetExclusionSuccess = (authkey: any) => ({
    type: InsuranceActions.GET_EXCLUSION_SUCCESS,
    payload: authkey,
});

export const fetchGetExclusionError = (error: any) => ({
    type: InsuranceActions.GET_EXCLUSION_ERROR,
    payload: error,
});

export const fetchGetExclusion = (network_id) => {
    return ApiAction({
        url: `${exclusionUrl}/${network_id}`,
        method: 'GET',
        onLoading: fetchGetExclusionPending,
        onSuccess: fetchGetExclusionSuccess,
        onError: fetchGetExclusionError,
    });
};
