import { fromJS } from 'immutable';
import * as types from './constants';

const initialState = fromJS({
  getFTPServersInProgress: false,
  FTPServers: [],
  getFTPServersError: false,
});

function createReducer(state = initialState, action) {
  switch (action.type) {
    case types.GET_FTP_SERVERS_REQUEST:
      return state
        .set('getFTPServersInProgress', true)
        .set('FTPServers', [])
        .set('getFTPServersInProgress', true);
    case types.GET_FTP_SERVERS_SUCCESS:
      return state
        .set('getFTPServersInProgress', false)
        .set('FTPServers', action.data)
        .set('getFTPServersInProgress', false);
    case types.GET_FTP_SERVERS_FAILURE:
      return state
        .set('getFTPServersInProgress', false)
        .set('FTPServers', [])
        .set('getFTPServersInProgress', true);
    default:
      return state;
  }
}

export default createReducer;
