"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.stimulusSchema = exports.sessionItemSchema = exports.sessionItemResultSchema = exports.shareBankSchema = exports.resumeDataSchema = exports.quizSessionSchema = exports.quizSessionResultSchema = exports.quizSessionEventSchema = exports.quizSchema = exports.quizEntrySchema = exports.quizEntriesSchema = exports.quizAnalysisSchema = exports.qtiImportSchema = exports.itemSchema = exports.itemAnalysisSchema = exports.interactionTypeSchema = exports.bankSchema = exports.bankEntrySchema = void 0;

var _normalizr = require("normalizr");

var bankSchema = new _normalizr.schema.Entity('banks');
exports.bankSchema = bankSchema;
var bankEntrySchema = new _normalizr.schema.Entity('bankEntries');
exports.bankEntrySchema = bankEntrySchema;
var interactionTypeSchema = new _normalizr.schema.Entity('interactionTypes');
exports.interactionTypeSchema = interactionTypeSchema;
var itemAnalysisSchema = new _normalizr.schema.Entity('itemAnalyses', {}, {
  idAttribute: 'item_id'
});
exports.itemAnalysisSchema = itemAnalysisSchema;
var quizAnalysisSchema = new _normalizr.schema.Entity('quizAnalyses', {}, {
  idAttribute: 'quiz_id'
});
exports.quizAnalysisSchema = quizAnalysisSchema;
var itemSchema = new _normalizr.schema.Entity('items');
exports.itemSchema = itemSchema;
var qtiImportSchema = new _normalizr.schema.Entity('qtiImports');
exports.qtiImportSchema = qtiImportSchema;
var quizSchema = new _normalizr.schema.Entity('quizzes');
exports.quizSchema = quizSchema;
var quizSessionEventSchema = new _normalizr.schema.Entity('quizSessionEvents', {}, {
  idAttribute: 'created_at' // indexed by createdAt

});
exports.quizSessionEventSchema = quizSessionEventSchema;
var shareBankSchema = new _normalizr.schema.Entity('sharedBanks');
exports.shareBankSchema = shareBankSchema;
var quizSessionResultSchema = new _normalizr.schema.Entity('quizSessionResults');
exports.quizSessionResultSchema = quizSessionResultSchema;
var quizSessionSchema = new _normalizr.schema.Entity('quizSessions');
exports.quizSessionSchema = quizSessionSchema;
var quizEntrySchema = new _normalizr.schema.Entity('quizEntry');
exports.quizEntrySchema = quizEntrySchema;
var quizEntriesSchema = new _normalizr.schema.Entity('quizEntries');
exports.quizEntriesSchema = quizEntriesSchema;
var resumeDataSchema = new _normalizr.schema.Entity('resumeData');
exports.resumeDataSchema = resumeDataSchema;
var sessionItemResultSchema = new _normalizr.schema.Entity('sessionItemResults');
exports.sessionItemResultSchema = sessionItemResultSchema;
var sessionItemSchema = new _normalizr.schema.Entity('sessionItems');
exports.sessionItemSchema = sessionItemSchema;
var stimulusSchema = new _normalizr.schema.Entity('stimuli'); // =================
//   relationships
// =================

exports.stimulusSchema = stimulusSchema;
bankEntrySchema.define({
  entry: new _normalizr.schema.Union({
    Item: itemSchema,
    Stimulus: stimulusSchema
  }, function (value, parent, key) {
    return parent.entry_type;
  })
});
itemSchema.define({
  interaction_type: interactionTypeSchema
});
stimulusSchema.define({});
quizSchema.define({
  items: [itemSchema],
  // Probably shouldn't have this at the root anymore...
  quizEntries: [quizEntrySchema],
  itemAnalyses: [itemAnalysisSchema],
  quizAnalysis: quizAnalysisSchema
});
var quizEntryNestedDef = {
  entry: new _normalizr.schema.Union({
    Bank: bankSchema,
    BankEntry: bankEntrySchema,
    Item: itemSchema,
    Stimulus: stimulusSchema
  }, function (value, parent, key) {
    return parent.entry_type;
  })
};
quizEntrySchema.define(quizEntryNestedDef);
quizEntriesSchema.define(quizEntryNestedDef); // 'item' is within the sessionItem, but it should remain
// denormalized because sessionItems of the same id can
// actually represent different objects
// however we do want to normalize the interaction types
// within it

sessionItemSchema.define({
  item: {
    interaction_type: interactionTypeSchema
  }
});
sessionItemResultSchema.define({
  quiz_session: quizSessionSchema,
  session_items: [sessionItemSchema]
});
quizSessionSchema.define({
  authoritative_result: quizSessionResultSchema,
  quiz: quizSchema,
  quiz_session_results: [quizSessionResultSchema]
});
quizSessionEventSchema.define({
  quiz_session: quizSessionSchema
});