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

'use strict';

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const LOG_LEVEL_LIST = [
  'debug',
  'info',
  'warn',
  'alert',
  'error',
  'crit',
  'fatal',
];

const LogSchema = new Schema({
  created: { type: Date, default: Date.now, required: true, index: -1, expires: '7d' },
  component: {
    name: { type: String, required: true },
    slug: { type: String, required: true, index: 1 },
  },
  level: { type: String, enum: LOG_LEVEL_LIST, required: true, index: true },
  message: { type: String },
  metadata: { type: Schema.Types.Mixed },
});

module.exports = mongoose.model('Log', LogSchema);
