'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _immutable = require('immutable');

var _reduxRecord = require('./reduxRecord');

var _reduxRecord2 = _interopRequireDefault(_reduxRecord);

var _QuizSessionEvent = require('./QuizSessionEvent');

var _QuizSessionEvent2 = _interopRequireDefault(_QuizSessionEvent);

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

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

var QuizSession = function (_ReduxRecord) {
  (0, _inherits3.default)(QuizSession, _ReduxRecord);

  function QuizSession() {
    (0, _classCallCheck3.default)(this, QuizSession);
    return (0, _possibleConstructorReturn3.default)(this, (QuizSession.__proto__ || Object.getPrototypeOf(QuizSession)).apply(this, arguments));
  }

  (0, _createClass3.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)();
    }

    // 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 _QuizSessionEvent2.default(data);
      });
    }
  }, {
    key: 'findAuthoritativeResult',
    value: function findAuthoritativeResult() {
      return this.stateHelper().findQuizSessionResult(this.authoritativeResult);
    }
  }, {
    key: 'userDisplayName',
    value: function userDisplayName() {
      // Still accurate?
      var email = void 0,
          fullName = void 0,
          givenName = void 0;
      if (this.user) {
        var _user$toJS = this.user.toJS();

        email = _user$toJS.email;
        fullName = _user$toJS.fullName;
        givenName = _user$toJS.givenName;
      }
      return fullName || givenName || email || '';
    }
  }]);
  return QuizSession;
}((0, _reduxRecord2.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;