import mongoose, { Document } from 'mongoose';

import { MODEL_NAMES } from './_models';
import { IBorrowerGroup } from '../interfaces/group.interface';

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

interface ICustomerAPGroupDocument extends IBorrowerGroup, Document {
}

export const CustomerAPGroupSchema = new mongoose.Schema(
  {
    groupName: {
      type: String,
      trim: true,
      required: true,
    },
    borrowerId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.complianceItems,
      required: true,
    },
    items: [String],
    __v: { type: Number, select: false },
  },
  { timestamps: true }
);

CustomerAPGroupSchema.plugin(mongooseLeanId);

export default mongoose.model<ICustomerAPGroupDocument>(MODEL_NAMES.customerAPGroups, CustomerAPGroupSchema);
