"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getFindResult = exports.default = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _actionCodes = require("../constants/actionCodes");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const handleRelationFindFulfilled = (state, action) => {
  const {
    subject,
    object,
    predicate
  } = action.meta;
  return state.setIn(['find', subject.csid, object.csid, predicate, 'result'], _immutable.default.fromJS(action.payload.data));
};
var _default = function _default() {
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _immutable.default.Map();
  let action = arguments.length > 1 ? arguments[1] : undefined;
  switch (action.type) {
    case _actionCodes.CLEAR_RELATION_STATE:
      return state.clear();
    case _actionCodes.RELATION_FIND_FULFILLED:
      return handleRelationFindFulfilled(state, action);
    case _actionCodes.SUBJECT_RELATIONS_UPDATED:
      return state.deleteIn(['find', action.meta.subject.csid]);
    default:
      return state;
  }
};
exports.default = _default;
const getFindResult = (state, subject, object, predicate) => state.getIn(['find', subject.csid, object.csid, predicate, 'result']);
exports.getFindResult = getFindResult;