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

'use strict';

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const NEWSLETTER_STATUS_LIST = ['draft', 'published', 'archived'];

const NewsletterSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: -1 },
  author: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' },
  title: { type: String, required: true },
  summary: { type: String },
  content: {
    html: { type: String, required: true, select: false, },
    text: { type: String, required: true, select: false, },
  },
  status: {
    type: String,
    enum: NEWSLETTER_STATUS_LIST,
    default: 'draft',
    required: true,
    index: true,
  },
});

module.exports = mongoose.model('Newsletter', NewsletterSchema);
