import mongoose from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface IExternalUserAccess {
  email: string;
  hashedPassword: string;
}

export type IExternalUserAccessDoc = mongoose.HydratedDocument<IExternalUserAccess>;

export interface IExternalUserAccessLean extends IExternalUserAccess {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

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

export type ExternalUserAccessModel = mongoose.Model<IExternalUserAccess>;

export const ExternalUserAccessSchema = new mongoose.Schema<IExternalUserAccess, ExternalUserAccessModel>(
  {
    email: {
      type: String,
      lowercase: true,
      unique: true,
    },
    hashedPassword: {
      type: String,
    },
  },
  {
    timestamps: { createdAt: true, updatedAt: true },
    versionKey: false,
  },
);

export const ExternalUserAccess = mongoose.model<IExternalUserAccess, ExternalUserAccessModel>(MODEL_NAMES.externalUserAccess, ExternalUserAccessSchema);
