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

export const getPoultryTransportByCodeService = createAsyncThunk(
  "GET_POULTRY_TRANSPORT_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-by-code/",
        {
          params: {
            code: params.code,
            type: params.type,
            page: params.page || 1,
            page_size: params.page_size || 10,
            date1: params.date1 || "",
            date2: params.date2 || "",
            search: params.search || "",
            province: params.province || "",
            product: params.product || "",
            from: params.from || "",
          },
        }
      );
      dispatch(LOADING_END());
      return { data, status };
    } catch (error) {
      dispatch(LOADING_END());
      return { error: error.response?.data || error.message };
    }
  }
);
