import mongoose, { Model } from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface IFinancialSpreadingExclusion {
  order: number;
  borrowerId: mongoose.Types.ObjectId;
  text: string;
}

export interface IFinancialSpreadingExclusionDoc extends IFinancialSpreadingExclusion, Document {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface IFinancialSpreadingExclusionLean extends IFinancialSpreadingExclusion {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface IFinancialSpreadingExclusionPlain extends Omit<IFinancialSpreadingExclusion, 'borrowerId'> {
  _id: string;
  borrowerId: string;
  createdAt: Date;
  updatedAt: Date;
}

export type IFinancialSpreadingExclusionModel = Model<IFinancialSpreadingExclusion>;

export const FinancialSpreadingExclusionSchema = new mongoose.Schema<IFinancialSpreadingExclusion, IFinancialSpreadingExclusionModel>(
  {
    order: {
      type: Number,
      required: true,
      trim: true,
    },
    borrowerId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.borrowers,
      required: true,
    },
    text: {
      type: String,
      required: false,
      trim: true,
      default: '',
    },
  },
  {
    timestamps: { createdAt: true, updatedAt: true },
  },
);

export const FinancialSpreadingExclusion = mongoose.model<IFinancialSpreadingExclusion, IFinancialSpreadingExclusionModel>(MODEL_NAMES.financialSpreadingExclusion, FinancialSpreadingExclusionSchema);
