import { UserAppData } from '../../types'
import * as ActionTypes from '../actionTypes'
import { UserAppDataDispatchTypes } from './types'

const initialState: UserAppData = {
  sigits: {},
  processedGiftWraps: [],
  blossomUrls: []
}

const reducer = (
  state = initialState,
  action: UserAppDataDispatchTypes
): UserAppData | null => {
  switch (action.type) {
    case ActionTypes.UPDATE_USER_APP_DATA:
      return {
        ...action.payload
      }

    case ActionTypes.UPDATE_PROCESSED_GIFT_WRAPS:
      return {
        ...state,
        processedGiftWraps: action.payload
      }

    case ActionTypes.RESTORE_STATE:
      return action.payload.userAppData || null

    default:
      return state
  }
}

export default reducer
