import mongoose from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface ICRMProspectNotification {
  prospectId: mongoose.Types.ObjectId;
  stageOne: boolean;
  stageTwo: boolean;
}

export type ICRMProspectNotificationDoc = mongoose.HydratedDocument<ICRMProspectNotification>;

export interface ICRMProspectNotificationLean extends ICRMProspectNotification {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface ICRMProspectNotificationPlain extends Omit<ICRMProspectNotification, 'prospectId'> {
  _id: string;
  prospectId: string;
  createdAt: Date;
  updatedAt: Date;
}

export type CRMProspectNotificationModel = mongoose.Model<ICRMProspectNotification>;

export const CRMProspectNotificationSchema = new mongoose.Schema<ICRMProspectNotification, CRMProspectNotificationModel>(
  {
    prospectId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.CRMProspects,
      required: true,
    },
    stageOne: {
      type: Boolean,
      required: true,
      default: false,
    },
    stageTwo: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  {
    timestamps: { createdAt: false, updatedAt: false },
    versionKey: false,
  },
);

export const CRMProspectNotification = mongoose.model<ICRMProspectNotification, CRMProspectNotificationModel>(MODEL_NAMES.prospectNotifications, CRMProspectNotificationSchema);
