// Import collections
import { getOccurrenceCollection } from '../../initCollections';

// Import shared types
import Occurrence from '../types/Occurrence';

// Import shared helpers
import genOccurrenceId from './genOccurrenceId';

/**
 * Add an occurrence to the db
 * @author Gabe Abrams
 * @author Ben Arnarsson
 * @param occurrence the occurrence to add
 */
const createOccurrence = async (occurrence: Occurrence) => {
  const occurrenceCollection = getOccurrenceCollection();
  await occurrenceCollection.insert({
    id: genOccurrenceId(occurrence),
    ...occurrence,
  });
};

export default createOccurrence;
