'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.QUIZ_SUBMISSION_EVENT = exports.SESSION_STARTED_OR_RESUMED_EVENT = exports.EVENT_RESPONSE = exports.RESPONSE = undefined;

var _humps = require('humps');

function eventType() {
  var eventTransform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (data) {
    return data;
  };

  return function (data) {
    var quizSessionId = data.quizSessionId,
        accountUuid = data.accountUuid;


    var createdAt = new Date().toISOString() + '|' + window.performance.now();
    var quizSessionKey = quizSessionId + '|' + accountUuid;

    var serializedData = JSON.stringify((0, _humps.decamelizeKeys)(Object.assign(eventTransform(data), { createdAt: createdAt })));

    // AWS-SDK uses capitalized properties :\
    return {
      Data: serializedData,
      PartitionKey: quizSessionKey
    };
  };
}

var RESPONSE = exports.RESPONSE = eventType(function (data) {
  // The resume (response_events) stream doesn't care about eventData contents
  // Clean them up!

  // Required to prevent modification of the source data
  var adjustedData = Object.assign({}, data);
  adjustedData.eventData = Object.assign({}, data.eventData);

  'position userResponse itemId'.split(' ').forEach(function (prop) {
    adjustedData[prop] = adjustedData.eventData[prop];
    delete adjustedData.eventData[prop];
  });

  return adjustedData;
});

var EVENT_RESPONSE = exports.EVENT_RESPONSE = eventType();
var SESSION_STARTED_OR_RESUMED_EVENT = exports.SESSION_STARTED_OR_RESUMED_EVENT = eventType();
var QUIZ_SUBMISSION_EVENT = exports.QUIZ_SUBMISSION_EVENT = eventType();