// page.js
// Copyright (C) 2021 Digital Telepresence, LLC
// License: Apache-2.0

'use strict';

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

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

const PageSchema = new Schema({
  title: { type: String, required: true },
  slug: { type: String, required: true, lowercase: true, unique: true },
  image: {
    header: { type: Schema.ObjectId, ref: 'Image' },
    icon: { type: Schema.ObjectId, ref: 'Image' },
  },
  content: { type: String, required: true, select: false },
  status: { type: String, enum: PAGE_STATUS_LIST, default: 'draft', index: true },
  menu: {
    icon: { type: String, required: true },
    label: { type: String, required: true },
    order: { type: Number, default: 0, required: true },
    parent: { type: Schema.ObjectId, index: 1, ref: 'Page' },
  },
});

module.exports = mongoose.model('Page', PageSchema);