import {
  ACTION_APP_CLEAN_TOKEN,
  ACTION_APP_SET_PUSH_TOKEN,
  ACTION_APP_SET_TOKEN,
  ACTION_APP_SET_DEVICE,
  ACTION_APP_CLEAN_DEVICE,
  ACTION_APP_SET_USER,
  ACTION_APP_CLEAN_USER,
  ACTION_APP_SET_NOTIFICATION,
  ACTION_APP_CHANGE_NOTIFICATION,
  ACTION_APP_SET_PROJECT_ID,
  ACTION_APP_CLEAN_PROJECT_ID,
  ACTION_APP_SET_LANGUAGE,
  ACTION_APP_SET_SERVER_MODE,
  ACTION_SET_POPUP_NOTIFICATION
} from './action'

const initialState = {
  token: null,
  push_token: null,
  device: null,
  user: null,
  notification: null,
  project_id: null,
  lang: null,
  server_mode: 'production',
}

export default function (state = initialState, action) {
  switch (action.type) {
    case ACTION_APP_SET_LANGUAGE:
      return { ...state, lang: action.lang }
    case ACTION_APP_SET_TOKEN:
      return { ...state, token: action.token }
    case ACTION_APP_CLEAN_TOKEN:
      return { ...state, token: null }
    case ACTION_APP_SET_PUSH_TOKEN:
      return { ...state, push_token: action.pushToken }
    case ACTION_APP_SET_DEVICE:
      return { ...state, device: action.device }
    case ACTION_APP_CLEAN_DEVICE:
      return { ...state, device: null }
    case ACTION_APP_SET_USER:
      return { ...state, user: action.user }
    case ACTION_APP_CLEAN_USER:
      return { ...state, user: null }
    case ACTION_APP_SET_NOTIFICATION:
      return { ...state, count_noti: action.count_noti }
    case ACTION_APP_CHANGE_NOTIFICATION:
      return { ...state, notification: action.notification }
    case ACTION_APP_SET_PROJECT_ID:
      return { ...state, project_id: action.project_id }
    case ACTION_APP_CLEAN_PROJECT_ID:
      return { ...state, project_id: null }
    case ACTION_APP_SET_SERVER_MODE:
      return { ...state, server_mode: action.mode }
    case ACTION_SET_POPUP_NOTIFICATION:
      return { ...state, popup_notification: action.popup_notification }
    default:
      return state
  }
}
