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

// 회원 등록카드 PIN CODE 입력 체크 IF-LGSP-336
export const getMyInfoCardPincodeCheck =
  (params, callback) => (dispatch, getState) => {
    const { mbrNo, pinCd } = params;

    dispatch(
      changeAppStatus({
        showLoadingPanel: { show: true, type: "wait", showMessage: true },
      })
    );

    const onSuccess = (response) => {
      console.log("getMyInfoCardPincodeCheck onSuccess ", response);

      dispatch({
        type: types.GET_MY_INFO_CARD_PINCODE_CHECK,
        payload: response.data,
      });

      if (response.data.retCode !== 0) {
        dispatch(
          changeAppStatus({
            showLoadingPanel: { show: false, showMessage: false },
          })
        );
      }

      if (callback) {
        callback(response.data);
      }
    };

    const onFail = (error) => {
      console.error("getMyInfoCardPincodeCheck onFail ", error);
      dispatch(
        changeAppStatus({
          showLoadingPanel: { show: false, showMessage: false },
        })
      );
    };

    TAxios(
      dispatch,
      getState,
      "get",
      URLS.GET_MY_INFO_CARD_PINCODE_CHECK,
      { mbrNo, pinCd },
      {},
      onSuccess,
      onFail
    );
  };
