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

export const slaughterGetDispenserUserInfoService = createAsyncThunk(
  "SLAUGHTER_GET_DISPENSER_USER_INFO_SERVICE",
  async (params, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { data, status } = await axios.get(`get_dispenser_user_info`, {
        params: {
          national_code: params.national_code || "",
          role_key: params.role_key || "",
        },
      });
      dispatch(LOADING_END());
      if (data && data.status === false) {
        return {
          error: data.errorDescription || "خطا در دریافت اطلاعات",
        };
      }
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return {
        error:
          e.response?.data?.errorDescription ||
          e.response?.data?.result ||
          e.response?.data?.message ||
          "خطا در دریافت اطلاعات",
      };
    }
  }
);
