import { Schema, model } from 'mongoose';
import { paginate, toJSON } from '@/shared/utils/plugins';
import {
  IPushNotificationDoc,
  IPushNotificationModel,
} from './pushNotification.interface';

const pushNotificationSchema = new Schema<IPushNotificationDoc>(
  {
    title: { type: String, required: true, trim: true },
    description: { type: String, required: true, trim: true },
    image: { type: String },
    type: {
      type: String,
      required: true,
    },
    receivedTo: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    read: {
      type: Boolean,
      default: false,
    },
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    updatedBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    appRedirect: {
      screenType: {
        type: String,
      },
      screenId: {
        type: String,
      },
    },
  },
  { timestamps: true },
);

pushNotificationSchema.plugin(toJSON);
pushNotificationSchema.plugin(paginate);

export const PushNotification = model<
  IPushNotificationDoc,
  IPushNotificationModel
>('PushNotification', pushNotificationSchema);
