import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";

export const vetFarmCancelBarService = createAsyncThunk(
  "VET_FARM_CANCEL_BAR_SERVICE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    try {
      const { data, status } = await axios.delete(
        "kill_house_request/0/?delete_bar&",
        {
          params: {
            kill_house_request_key: d.kill_house_request_key,
            message: d.message,
            role: getRoleFromUrl(),
          },
        }
      );
      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e.response.data.result };
    }
  }
);
