'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.get = get;

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _idGenerator = require('../actions/idGenerator');

var _logout = require('../actions/logout');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = (state = _immutable2.default.Map(), action) => {
  switch (action.type) {
    case _idGenerator.ADD_ID_GENERATORS:
      return state.mergeDeep(_immutable2.default.fromJS(action.payload));
    case _idGenerator.READ_ID_GENERATOR_FULFILLED:
      return state.setIn([action.meta.idGeneratorName, 'sample'], action.payload.data.idgenerator.displayid);
    case _logout.LOGOUT_FULFILLED:
      return state.map(idGeneratorState => idGeneratorState.delete('sample'));
    default:
      return state;
  }
};

function get(state, idGeneratorName) {
  return state.get(idGeneratorName);
}