import mongoose, { Document } from 'mongoose';

import { MODEL_NAMES } from './_models';

const mongooseLeanId = require('../plugins/id.plugin');

export interface IMappedGroup {
  borrowerId: string;
  groupType: string;
  group1: string;
  group2: string;
}

export interface IMappedGroupDocument extends IMappedGroup, Document {
}

export const MappedGroupSchema = new mongoose.Schema(
  {
    borrowerId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.borrowers,
      required: true,
    },
    group1: {
      type: String,
      trim: true,
      required: true,
    },
    group2: {
      type: String,
      trim: true,
      required: true,
    },
    groupType: {
      type: String,
      trim: true,
      required: true,
    },
    __v: { type: Number, select: false },
  },
  { timestamps: true }
);

MappedGroupSchema.plugin(mongooseLeanId);

export default mongoose.model<IMappedGroupDocument>(MODEL_NAMES.mappedGroups, MappedGroupSchema);
