'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);

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

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

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

  (0, _createClass3.default)(SessionItemResult, [{
    key: 'getItem',
    value: function getItem() {
      return this.stateHelper().findSessionItem(this.id).getItem();
    }
  }, {
    key: 'defaultResult',
    value: function defaultResult(sessionItem) {
      var defaultResultData = {
        attempt: 1,
        itemId: sessionItem.getItem().id,
        position: sessionItem.position,
        id: sessionItem.id
      };

      return new SessionItemResult(defaultResultData, this.getState());
    }
  }, {
    key: 'getWorkingInstance',
    value: function getWorkingInstance() {
      var modificationData = this.merge(this.getState().getIn(['modifications', 'sessionItemResults', this.id], (0, _immutable.Map)()));

      return new SessionItemResult(modificationData, this.getState());
    }
  }, {
    key: 'hasModifications',
    value: function hasModifications() {
      return !(0, _immutable.is)(this.getWorkingInstance(), this);
    }
  }, {
    key: 'isLoaded',
    value: function isLoaded() {
      return this.itemId !== null;
    }
  }, {
    key: 'isGraded',
    value: function isGraded() {
      return !!this.gradedAt;
    }
  }]);
  return SessionItemResult;
}((0, _reduxRecord2.default)({
  attempt: null,
  feedback: (0, _immutable.Map)(),
  gradedAt: null,
  graderId: null,
  gradingMethod: null,
  id: null,
  itemId: null,
  regradeInfo: null,
  position: null,
  score: null,
  scoredData: (0, _immutable.Map)()
}));

exports.default = SessionItemResult;