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

export const provincePriceEditService = createAsyncThunk(
  "PROVINCE_PRICE_EDIT_SERVICE",
  async (d, { dispatch }) => {
    try {
      dispatch(LOADING_START());

      const { data, status } = await axios.put(
        `chicken-commission-prices/${d.id}/`,
        {
          kill_house_price: d.kill_house_price,
          wholesaler_price: d.wholesaler_price,
          retailer_price: d.retailer_price,
        }
      );

      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e?.response?.data?.result || "خطایی رخ داده است" };
    }
  }
);
