"use strict";

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

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

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

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

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

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

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

var _immutable = require("immutable");

var _reduxRecord = _interopRequireDefault(require("./reduxRecord"));

var _QuizSessionEvent = _interopRequireDefault(require("./QuizSessionEvent"));

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

var QuizSession =
/*#__PURE__*/
function (_ReduxRecord) {
  (0, _inherits2.default)(QuizSession, _ReduxRecord);

  function QuizSession() {
    (0, _classCallCheck2.default)(this, QuizSession);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(QuizSession).apply(this, arguments));
  }

  (0, _createClass2.default)(QuizSession, [{
    key: "isLoaded",
    // Helpers
    value: function isLoaded() {
      return this.id !== '0';
    }
  }, {
    key: "isOneQuestionAtATime",
    value: function isOneQuestionAtATime() {
      return this.oneAtATimeType === 'question';
    } // Status helpers

  }, {
    key: "pending",
    value: function pending() {
      return this.status === _constants.PENDING;
    }
  }, {
    key: "starting",
    value: function starting() {
      return this.status === _constants.STARTING;
    }
  }, {
    key: "creatingSessionItems",
    value: function creatingSessionItems() {
      return this.status === _constants.CREATING_SESSION_ITEMS;
    }
  }, {
    key: "failedToStart",
    value: function failedToStart() {
      return this.status === _constants.FAILED_TO_START;
    }
  }, {
    key: "inProgress",
    value: function inProgress() {
      return this.status === _constants.IN_PROGRESS;
    }
  }, {
    key: "reopeningGraded",
    value: function reopeningGraded() {
      return this.status === _constants.REOPENING_GRADED;
    }
  }, {
    key: "creatingResponses",
    value: function creatingResponses() {
      return this.status === _constants.CREATING_RESPONSES;
    }
  }, {
    key: "autoGrading",
    value: function autoGrading() {
      return this.status === _constants.AUTOGRADING;
    }
  }, {
    key: "needsGrading",
    value: function needsGrading() {
      return this.status === _constants.NEEDS_GRADING;
    }
  }, {
    key: "failed",
    value: function failed() {
      return this.status === _constants.FAILURE;
    }
  }, {
    key: "graded",
    value: function graded() {
      return this.status === _constants.GRADED;
    }
  }, {
    key: "taking",
    value: function taking() {
      return this.starting() || this.creatingSessionItems() || this.inProgress() || this.reopeningGraded();
    }
  }, {
    key: "submitted",
    value: function submitted() {
      return this.creatingResponses() || this.autoGrading() || this.needsGrading() || this.graded() || this.failed();
    }
  }, {
    key: "pins",
    value: function pins() {
      return this.takingData.get('pins') || (0, _immutable.List)();
    }
  }, {
    key: "timeAllowed",
    value: function timeAllowed() {
      return this.takingData.get('timeAllowed');
    } // Relationships

  }, {
    key: "getQuiz",
    value: function getQuiz() {
      return this.stateHelper().findQuiz(this.quiz);
    }
  }, {
    key: "getSessionItems",
    value: function getSessionItems() {
      return this.getRelationList('sessionItems', 'findSessionItem');
    }
  }, {
    key: "getQuizSessionResults",
    value: function getQuizSessionResults() {
      return this.getRelationList('quizSessionResults', 'findQuizSessionResult');
    }
  }, {
    key: "getResumeData",
    value: function getResumeData() {
      return this.getRelationList('resumeData', 'findTakingResponse');
    }
  }, {
    key: "getEvents",
    value: function getEvents() {
      return this.getState().getIn(['quizSessionEvents', this.id], (0, _immutable.List)()).map(function (data) {
        return new _QuizSessionEvent.default(data);
      });
    }
  }, {
    key: "findAuthoritativeResult",
    value: function findAuthoritativeResult() {
      return this.stateHelper().findQuizSessionResult(this.authoritativeResult);
    }
  }, {
    key: "userDisplayName",
    value: function userDisplayName() {
      // Still accurate?
      var email, fullName, givenName;

      if (this.user) {
        var _this$user$toJS = this.user.toJS();

        email = _this$user$toJS.email;
        fullName = _this$user$toJS.fullName;
        givenName = _this$user$toJS.givenName;
      }

      return fullName || givenName || email || '';
    }
  }]);
  return QuizSession;
}((0, _reduxRecord.default)({
  acceptedStudentAccessCode: false,
  accountUuid: '',
  allowBacktracking: true,
  authoritativeResult: null,
  disableTimer: false,
  elapsedTime: null,
  endAt: null,
  eventCreationToken: null,
  extraTimeInSeconds: null,
  id: '0',
  ipIsAllowed: null,
  kinesisCredentials: {},
  oneAtATimeType: null,
  quiz: null,
  // this is really a quizId
  quizSessionResults: (0, _immutable.List)(),
  resumeData: (0, _immutable.List)(),
  sessionItems: (0, _immutable.List)(),
  sessionItemsCount: null,
  startAt: null,
  status: '',
  takingData: (0, _immutable.Map)(),
  timerMultiplier: null,
  user: (0, _immutable.Map)() // Good candidate for another Record - Still relevant?

}));

exports.default = QuizSession;