import { Schema } from "mongoose";
import { applyIdTransform, registerModel, stringId } from "../schema";

const NotificationSchema = new Schema(
  {
    _id: stringId,
    userId: { type: String, ref: "User", required: true },
    titleAr: { type: String, required: true },
    titleEn: { type: String, required: true },
    messageAr: { type: String, required: true },
    messageEn: { type: String, required: true },
    link: { type: String, default: undefined },
    readAt: { type: Date, default: undefined },
  },
  { timestamps: { createdAt: true, updatedAt: false } },
);

NotificationSchema.index({ userId: 1, createdAt: -1 });
NotificationSchema.index({ userId: 1, readAt: 1 });
applyIdTransform(NotificationSchema);

export const Notification = registerModel("Notification", NotificationSchema);
