text: import api from './api';
  import axios from 'axios';
  import sendAlert from '../helpers/alert';
  import validateUserPermission from '../helpers/validateUserPermission';
  
  /**
   * Fetches a payment
   * @param {{
   * END_POINT: string
   * showAlert: boolean
   * controller: Function
   * }}
   */
  export const fetchPayment = async ({
    END_POINT = '',
    showAlert = false,
    controller = () => {},
  }) => {
    let paymentExists = false;
    let payment = [];
    try {
      const {
        data: { success, message, pagamento },
      } = await api.get(END_POINT, { signal: controller.signal });
      paymentExists = success;
      payment = pagamento || [];
      if (showAlert) sendAlert(success, message);
    } catch (error) {
      if (axios.isCancel(error)) {
        console.log('successfully aborted');
      } else {
        console.error(error);
      }
    }
    return { paymentExists, payment };
  };
  
  /**
   * Register a payment
   * @param {{
   * END_POINT: string
   * showAlert: boolean
   * controller: Function
   * values: object
   * }}
   */
  export const sendPayment = async ({
    END_POINT,
    values,
    showAlert,
    controller,
  }) => {
    let statusPayment = false;
    let payment = [];
    try {
      const {
        data: { success, pagamento, message },
        data,
      } = await api.post(
        END_POINT,
        {
          ...values,
        },
        { signal: controller.signal }
      );
      console.log(data);
      statusPayment = success;
      payment = pagamento;
      if (showAlert) sendAlert(success, message);
    } catch (error) {
      if (axios.isCancel(error)) {
        console.log('successfully aborted');
      } else {
        console.error(error);
      }
    }
    return { payment, statusPayment };
  };
  
  /**
   * Updates a payment
   * @param {{
   * END_POINT: string
   * showAlert: boolean
   * controller: Function
   * values: object
   * }}
   */
  export const updatePayment = async ({
    END_POINT,
    values,
    showAlert,
    controller,
  }) => {
    let paymentUpdated = false;
    try {
      if (!validateUserPermission()) {
        sendAlert(false, 'Alterações não permitidas');
        return 0;
      }
      const {
        data: { success, message },
        data,
      } = await api.put(
        END_POINT,
        {
          ...values,
        },
        { signal: controller.signal }
      );
      console.log(data);
      paymentUpdated = success;
      if (showAlert) sendAlert(success, message);
    } catch (error) {
      if (axios.isCancel(error)) {
        console.log('successfully aborted');
      } else {
        console.error(error);
      }
    }
    return { paymentUpdated };
  };
  
  /**
   * Deletes a payment
   * @param {{
   * END_POINT: string
   * showAlert: boolean
   * controller: Function
   * values: object
   * }}
   */
  export const deletePayment = async ({
    END_POINT,
    values,
    showAlert,
    controller,
  }) => {
    let paymentDeleted = false;
    try {
      if (!validateUserPermission()) {
        sendAlert(false, 'Alterações não permitidas');
        return 0;
      }
      const {
        data: { success, message },
        data,
      } = await api.delete(
        END_POINT,
        {
          data: values,
        },
        { signal: controller.signal }
      );
      paymentDeleted = success;
      if (showAlert) sendAlert(success, message);
    } catch (error) {
      if (axios.isCancel(error)) {
        console.log('successfully aborted');
      } else {
        console.error(error);
      }
    }
    return { paymentDeleted };
  };
  