"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 SessionItemResult =
/*#__PURE__*/
function (_ReduxRecord) {
  (0, _inherits2.default)(SessionItemResult, _ReduxRecord);

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

  (0, _createClass2.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, _reduxRecord.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;