'use strict';

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

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

var _Fetcher2 = _interopRequireDefault(_Fetcher);

var _callHandlers = require('../../common/api/callHandlers');

var _reporting = require('../../common/actions/reporting');

var _quizzes = require('../../common/actions/quizzes');

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

function getQuizAnalysis(quizId) {
  var url = '/api/quizzes/' + quizId + '/stats/quiz_analysis';

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.default({
      onError: function onError() {
        return (0, _reporting.markQuizAnalysisNotFound)(quizId);
      }
    });

    return fetcher.get(url).then(function (response) {
      dispatch([(0, _callHandlers.handleQuizAnalysisResponse)(response), (0, _quizzes.associateQuizAnalysis)(quizId, response)]);
    });
  };
}