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

// Featured Brands 정보 조회 IF-LGSP-304
// @@pyh Todo, 기존의 key가 brandList에서 brandInfo로 변경 됨에 따라 함수명 또한 바뀔 수 있음 (문서 확인 후 변경 처리)
export const getBrandList = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("@@ getBrandList onSuccess ", response.data);

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

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

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_BRAND_LIST,
    {},
    {},
    onSuccess,
    onFail
  );
};

// Featured Brands LAYOUT (shelf) 정보 조회 IF-LGSP-305
export const getBrandLayoutInfo = (props) => (dispatch, getState) => {
  const { patnrId } = props;

  const onSuccess = (response) => {
    console.log("@@ getBrandLayoutInfo onSuccess ", response.data);

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

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

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_BRAND_LAYOUT_INFO,
    { patnrId },
    {},
    onSuccess,
    onFail
  );
};

// Featured Brands Live 채널 정보 조회 IF-LGSP-306
export const getBrandLiveChannelInfo = (props) => (dispatch, getState) => {
  const { patnrId } = props;

  const onSuccess = (response) => {
    console.log("@@ getBrandLiveChannelInfo onSuccess ", response.data);

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

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

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_BRAND_LIVE_CHANNEL_INFO,
    { patnrId },
    {},
    onSuccess,
    onFail
  );
};

// Featured Brands Today's Deals 정보 조회 IF-LGSP-307
export const getBrandTSVInfo = (props) => (dispatch, getState) => {
  const { patnrId } = props;

  const onSuccess = (response) => {
    console.log("@@ getBrandTSVInfo onSuccess ", response.data);

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

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

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_BRAND_TODAYS_DEALS,
    { patnrId },
    {},
    onSuccess,
    onFail
  );
};
