// emoji-reaction.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0

'use strict';

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const REACTION_LIST = [
  'clap',
  'fire',
  'happy',
  'laugh',
  'angry',
  'honk',
];

const EmojiReactionSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: -1, expires: '30d' },

  /*
   * The thing for which a reaction is being filed.
   */
  subjectType: { type: String, required: true },
  subject: { type: Schema.ObjectId, required: true, index: 1, refPath: 'subjectType' },

  /*
   * The user creating the reaction
   */
  userType: { type: String, required: true },
  user: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' },

  reaction: { type: String, enum: REACTION_LIST, required: true },
  timestamp: { type: Number },
});

module.exports = mongoose.model('EmojiReaction', EmojiReactionSchema);