import { Schema, model } from 'mongoose';
import { paginate, toJSON } from '@/shared/utils/plugins';
import { INotificationDoc, INotificationModel } from './notification.interface';
import {
  NotificationDevice,
  NotificationStatus,
  UserType,
} from './notification.constant';

const notificationSchema = new Schema<INotificationDoc>(
  {
    title: { type: String, required: true, trim: true },
    description: { type: String, required: true, trim: true },
    image: { type: String, default: '' },
    userType: {
      type: String,
      enum: Object.values(UserType),
      default: UserType.ALL,
    },
    device: {
      type: String,
      enum: Object.values(NotificationDevice),
      default: NotificationDevice.ALL,
    },
    status: {
      type: String,
      enum: Object.values(NotificationStatus),
      default: NotificationStatus.SEND,
    },
    scheduleDateTime: {
      type: String,
      default: null,
    },
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    updatedBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
  },
  { timestamps: true },
);

notificationSchema.plugin(toJSON);
notificationSchema.plugin(paginate);

export const Notification = model<INotificationDoc, INotificationModel>(
  'Notification',
  notificationSchema,
);
