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

export const managementSendSms = createAsyncThunk(
  "MANAGEMENT_SEND_SMS",
  async (d, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { id, ...rest } = d;
      const { data, status } = await axios.put(
        `management-send-sms/${id}/`,
        rest
      );
      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e.response?.data?.result || "خطا در ارسال پیامک" };
    }
  }
);
