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

'use strict';

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const ContentVoteSchema = new Schema({
  created: { type: Date, default: Date.now, required: true },
  resourceType: { type: String, required: true },
  resource: { type: Schema.ObjectId, required: true, refPath: 'resourceType' },
  user: { type: Schema.ObjectId, required: true, ref: 'User' },
  vote: { type: String, enum: ['up','down'], required: true },
});

ContentVoteSchema.index({
  user: 1,
  resource: 1,
}, {
  unique: true,
  name: 'unique_user_content_vote',
});

module.exports = mongoose.model('ContentVote', ContentVoteSchema);