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

'use strict';

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

const REPORT_STATUS_LIST = ['new','resolved','ignored'];
const REPORT_CATEGORY_LIST = ['spam','violence','threat','porn','doxxing','faggot','other'];

const ContentReportSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: 1, expires: '30d' },
  user: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' },
  resourceType: { type: String, enum: ['Comment', 'ChatMessage'], required: true },
  resource: { type: Schema.ObjectId, required: true, index: 1, refPath: 'resourceType' },
  status: { type: String, enum: REPORT_STATUS_LIST, required: true, index: 1 },
  category: { type: String, enum: REPORT_CATEGORY_LIST, required: true },
  reason: { type: String },
});

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

module.exports = mongoose.model('ContentReport', ContentReportSchema);