import { Schema, model } from 'mongoose';
import { paginate, toJSON } from '@/shared/utils/plugins';
import {
  IActivityRemainderDoc,
  IActivityRemainderModel,
} from './activityRemainder.interface';
import { ActivityStatus, ActivityType } from '@/shared/constants/enum.constant';

const activityRemainderSchema = new Schema<IActivityRemainderDoc>(
  {
    activityId: {
      type: Schema.Types.ObjectId,
      ref: 'Activity',
    },
    leadId: {
      type: Schema.Types.ObjectId,
      ref: 'Lead',
    },
    contactId: {
      type: Schema.Types.ObjectId,
      ref: 'Contacts',
    },
    assignedTo: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    scheduleDateTime: {
      type: Date,
    },
    activityType: {
      type: String,
      enum: Object.values(ActivityType),
      required: true,
    },
    isNotificationSent: {
      type: Boolean,
      default: false,
    },
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    updatedBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    status: {
      type: String,
      enum: Object.values(ActivityStatus),
    },
  },
  {
    timestamps: true,
  },
);

activityRemainderSchema.plugin(toJSON);
activityRemainderSchema.plugin(paginate);

export const ActivityRemainder = model<
  IActivityRemainderDoc,
  IActivityRemainderModel
>('ActivityRemainder', activityRemainderSchema);
