import { types } from "../actions/actionTypes";

const initialState = {
  recommandedKeywordData: {},
  faqData: {},
  contactData: {},
  noticeData: {},
  favoriteData: {},
  favoriteFlagData: {},
  alertShowData: {},
  upComingData: {
    upComingChangeInfo: {},
    upComingAlertShow: {},
    upComingAlertShowKeys: {},
    upComingAlertShowChangeInfo: {},
  },
  setMyUpcomingUseAlertData: {},
  recentlyViewedData: {},
  recentlyViewedSuccess: null,
  favoriteRetCode: null,
  setMyPageTermsAgreeResult: { data: null, retCode: null, error: null },
};

export const myPageReducer = (state = initialState, action) => {
  switch (action.type) {
    case types.GET_MY_RECOMMANDED_KEYWORD:
      return {
        ...state,
        recommandedKeywordData: action.payload,
      };
    case types.GET_MY_FAQ_INFO:
      return {
        ...state,
        faqData: action.payload,
      };
    case types.GET_NOTICE:
      return {
        ...state,
        noticeData: action.payload,
      };
    case types.GET_MY_CUSTOMERS:
      return {
        ...state,
        contactData: action.payload,
      };
    case types.GET_MY_FAVORITE:
      return {
        ...state,
        favoriteData: action.payload,
        favoriteRetCode: action.retCode,
      };
    case types.CLEAR_FAVORITES:
      return {
        ...state,
        favoriteData: {},
        favoriteRetCode: null,
      };

    case types.DELETE_MY_FAVORITE:
      return {
        ...state,
        favoriteData: {
          ...state.favoriteData,
          favorites: action.payload,
        },
      };

    case types.DELETE_MY_UPCOMING_ALERT_SHOW:
      return {
        ...state,
        alertShowData: {
          ...state.alertShowData,
          alertShow: action.payload,
        },
      };

    case types.GET_MY_FAVORITE_FLAG:
      return {
        ...state,
        favoriteFlagData: action.payload,
      };

    case types.GET_MY_UPCOMING_CHANGE_INFO:
      return {
        ...state,
        upComingData: {
          ...state.upComingData,
          upComingChangeInfo: action.payload,
        },
      };

    case types.GET_MY_UPCOMING_ALERT_SHOW:
      return {
        ...state,
        upComingData: {
          ...state.upComingData,
          upComingAlertShow: action.payload,
        },
      };

    case types.GET_MY_UPCOMING_ALERT_SHOW_KEYS:
      return {
        ...state,
        upComingData: {
          ...state.upComingData,
          upComingAlertShowKeys: action.payload,
        },
      };

    case types.GET_UPCOMING_ALERT_SHOW_CHANGE_INFO:
      return {
        ...state,
        upComingData: {
          ...state.upComingData,
          upComingAlertShowChangeInfo: action.payload,
        },
      };
    case types.GET_MY_RECENTLY_VIEWED_INFO:
      return {
        ...state,
        recentlyViewedData: action.payload,
        recentlyViewedSuccess: action.retCode,
      };
    case types.CLEAR_RECENTLY_VIEWED_INFO:
      return {
        ...state,
        recentlyViewedData: {},
        recentlyViewedSuccess: null,
      };

    case types.SET_MY_UPCOMING_USE_ALERT:
      return {
        ...state,
        upComingData: {
          ...state.upComingData,
          upComingAlertShow: {
            ...state.upComingData.upComingAlertShow,
            upcomAlamUseFlag: action.payload,
          },
        },
      };

    case types.SET_MYPAGE_TERMS_AGREE_SUCCESS:
      return {
        ...state,
        setMyPageTermsAgreeResult: {
          data: action.payload,
          retCode: action.retCode,
          error: null,
        },
      };

    case types.SET_MYPAGE_TERMS_AGREE_FAIL:
      return {
        ...state,
        setMyPageTermsAgreeResult: {
          data: null,
          retCode: null,
          error: action.payload,
        },
      };

    default:
      return state;
  }
};
