import { URLS } from "../api/apiConfig";
import { TAxios } from "../api/TAxios";
import { types } from "./actionTypes";

export const addMainIndex = (index) => ({
  type: types.ADD_MAIN_INDEX,
  payload: index,
});

// SMS 송신 IF-LGSP-037
export const sendSms = (params) => (dispatch, getState) => {
  const {
    mbphNo,
    smsTpCd,
    patnrId,
    evntId,
    prdtId,
    smsText,
    curationId,
    hotelId,
    hotelNm,
    hotelDtlUrl,
    dvcIndex,
    entryMenu,
  } = params;

  const onSuccess = (response) => {
    console.log("sendSms onSuccess ", response.data);
    dispatch({
      type: types.SEND_SMS,
      payload: response.data.data,
      retCode: response.data.retCode,
    });
  };

  const onFail = (error) => {
    console.error("sendSms onFail ", error);
  };

  TAxios(
    dispatch,
    getState,
    "post",
    URLS.SEND_SMS,
    {},
    {
      dvcIndex,
      mbphNo,
      smsTpCd,
      patnrId,
      evntId,
      prdtId,
      smsText,
      curationId,
      hotelId,
      hotelNm,
      hotelDtlUrl,
      entryMenu,
    },
    onSuccess,
    onFail
  );
};

export const clearSMS = () => ({
  type: types.CLEAR_SMS,
});
