import { handleActions } from 'redux-actions';
import * as Actions from '../constants/actions';

const defaultUserDetails = {
  firstname: '',
  lastname: '',
  position: '',
  mobile: '',
  country: '',
  company: '',
  city: '',
  skype: '',
  email: '',
  companySite: '',
  image: ''
};

const defaultStoreState = {
  user: defaultUserDetails,
  isAuthenticated: false
}

const initialState: StoreState = defaultStoreState;

export default handleActions<StoreState, IUserDetails>({
  [Actions.SIGN_IN]: (state, action) => {
    return {...state, user: action.payload, isAuthenticated: true};
  },

  [Actions.FETCH_USER_DATA]: (state, action) => {
    return {...state, user: action.payload};
  },

  [Actions.CLEAR_USER_DATA]: (state, action) => {
    return {...state, user: defaultUserDetails, isAuthenticated: false};
  }
}, initialState);