'use strict';

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

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

var _Fetcher2 = _interopRequireDefault(_Fetcher);

var _constants = require('../../constants');

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

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

function getQuizSessions(quizId) {
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  var url = '/api/quizzes/' + quizId + '/quiz_sessions';

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.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/' + quizSessionId;

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.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/' + quizSessionId + '/reopen';

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.default({ callType: _constants.QUIZ_SESSION_REOPEN_CALL });
    return fetcher.post(url).then(function (response) {
      dispatch((0, _callHandlers.handleQuizSessionResponse)(response));
    });
  };
}