import ActionTypes from '../constants/actionTypes';
import Immutable, { List, Map } from 'immutable';

/**
 * Reducer voor de lijst met gebruikers
 */
export const userListReducer = (state = List([]), action) => {
  switch (action.type) {
    case ActionTypes.GET_USERLIST_SUCCESS:
      return List(action.users);
    default:
      return state;
  }
};

/**
 * Reducer voor de lijst met organisatiecodes
 */
export const organisationListReducer = (state = List([]), action) => {
  switch (action.type) {
    case ActionTypes.GET_ORGANISATIONLIST_SUCCESS:
      return List(action.organisationList);
    default:
      return state;
  }
};

/**
 * Reducer voor gebruikerdetails
 */
export const userDetailsReducer = (state = Map({}), action) => {
  switch (action.type) {
    case ActionTypes.SAVE_USER_ERROR:
      return Map(action.userDetails);
    case ActionTypes.SAVE_USER_SUCCESS:
      return Map(action.userDetails);
    case ActionTypes.GET_USERLIST_SUCCESS:
    case ActionTypes.GET_USER_RESET:
      return Map({});
    case ActionTypes.GET_USER_SUCCESS:
      return Map(action.userDetails);
    default:
      return state;
  }
};
