'use strict';

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

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

var _stateHelper = require('./stateHelper');

var _stateHelper2 = _interopRequireDefault(_stateHelper);

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

var whitelist = [_constants.QUIZ_SUBMISSION_EVENT, _constants.RESPONSE, _constants.SESSION_STARTED_OR_RESUMED_EVENT];

function serializeEvent(action) {
  var type = action.type;

  if (!whitelist.includes(type)) {
    return false;
  }

  var quizSession = _stateHelper2.default.activeQuizSession();

  var defaultEventData = {
    browserSessionId: _stateHelper2.default.getSessionId(),
    clientTimestamp: new Date()
  };

  var authoritativeData = {
    accountUuid: quizSession.accountUuid,
    eventCreationToken: quizSession.eventCreationToken,
    eventType: type,
    quizSessionId: quizSession.id
  };

  return Object.assign({
    eventData: Object.assign({}, action.payload, defaultEventData)
  }, authoritativeData);
}