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

export const getFileProcess = createAsyncThunk(
  "GET_FILE",
  async (id, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(`/Poultry_Request/${id}/`);
    dispatch(LOADING_END());

    return { data, status };
  }
);

export const getFileProcessOther = createAsyncThunk(
  "GET_FILE_OTHER",
  async (id, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      "process/?id=" + id + `&role=${getRoleFromUrl()}`
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);
