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

export const getPoultryTransportDashboardByCodeService = createAsyncThunk(
  "GET_POULTRY_TRANSPORT_DASHBOARD_BY_CODE_SERVICE",
  async (params, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { data, status } = await axios.get(
        "https://rsibackend.rasadyar.com/app/get-all-products-transport-dashboard-by-code/",
        {
          params: {
            code: params.code,
            type: params.type,
            date1: params.date1 || "",
            date2: params.date2 || "",
            search: params.search || "",
            product: params.product || "",
            province: params.province || "",
            from: params.from || "",
          },
        }
      );
      dispatch(LOADING_END());
      return { data, status };
    } catch (error) {
      dispatch(LOADING_END());
      return { error: error.response?.data || error.message };
    }
  }
);
