import { Schema, model, Document, Types } from 'mongoose'

const AlertViewSchema = new Schema(
	{
		user: {
			type: Types.ObjectId,
			ref: 'User',
			required: true,
		},
		alert: {
			type: Types.ObjectId,
			ref: 'Alert',
			required: true,
		},
		at: {
			type: Date,
			default: Date,
		},
	},
	{ versionKey: false }
)

AlertViewSchema.index({ user: 1, alert: 1 })

export interface IAlertView extends Document {
	_id: Types.ObjectId
	user: Types.ObjectId
	alert: Types.ObjectId
	at: Date
}

export const AlertView = model('AlertView', AlertViewSchema, 'alert-views')
