"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

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

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

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

function getQuizSessions(quizId) {
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var url = "/api/quizzes/".concat(quizId, "/quiz_sessions");
  return function (dispatch, getState) {
    var fetcher = new _Fetcher.default({
      callType: _constants.QUIZ_SESSIONS_FETCH_CALL
    });
    return fetcher.get(url, params).then(function (response) {
      dispatch((0, _callHandlers.handleQuizSessionsResponse)(response));
    });
  };
}

function getQuizSession(quizSessionId) {
  var url = "/api/quiz_sessions/".concat(quizSessionId);
  return function (dispatch, getState) {
    var fetcher = new _Fetcher.default({
      callType: _constants.QUIZ_SESSION_FETCH_CALL
    });
    return fetcher.get(url).then(function (response) {
      dispatch((0, _callHandlers.handleQuizSessionResponse)(response));
    });
  };
}

function reopenQuizSession(quizSessionId) {
  var url = "/api/quiz_sessions/".concat(quizSessionId, "/reopen");
  return function (dispatch, getState) {
    var fetcher = new _Fetcher.default({
      callType: _constants.QUIZ_SESSION_REOPEN_CALL
    });
    return fetcher.post(url).then(function (response) {
      dispatch((0, _callHandlers.handleQuizSessionResponse)(response));
    });
  };
}