'use strict';

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

var _Fetcher = require('../util/Fetcher');

var _Fetcher2 = _interopRequireDefault(_Fetcher);

var _helpers = require('./helpers');

var _tagAssociations = require('../actions/tagAssociations');

var _constants = require('@instructure/quiz-common/lib/constants');

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

var getItemTagAssociations = exports.getItemTagAssociations = function getItemTagAssociations(itemId) {
  var url = '/api/items/' + itemId + '/tag_associations';

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.default({
      callType: _constants.GET_ITEM_TAG_ASSOCIATIONS,
      onError: (0, _helpers.handleError)(dispatch)
    });

    return fetcher.get(url).then(function (response) {
      return dispatch((0, _tagAssociations.setTagAssociations)('Item', itemId, response));
    });
  };
};

var getStimulusTagAssociations = exports.getStimulusTagAssociations = function getStimulusTagAssociations(itemId) {
  var url = '/api/stimuli/' + itemId + '/tag_associations';

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.default({
      callType: _constants.GET_STIMULUS_TAG_ASSOCIATIONS,
      onError: (0, _helpers.handleError)(dispatch)
    });

    return fetcher.get(url).then(function (response) {
      return dispatch((0, _tagAssociations.setTagAssociations)('Stimulus', itemId, response));
    });
  };
};