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 cityGetPoultriesService = createAsyncThunk(
  "CITY_GET_POULTRIES_SERVICE",
  async (_, { dispatch }) => {
    const role = getRoleFromUrl();
    let obj = { role };
    if (role === "CityOperator" || role === "ProvinceOperator") {
      obj = { role, active_hatching: true };
    }
    dispatch(LOADING_START());
    const { data, status } = await axios.get("get-all-poultry/", {
      params: obj,
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);
