import mongoose, { Model } from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface IFinancialSpreadingSummary {
  borrowerId: mongoose.Types.ObjectId;
  rawData: string;
  summary: string;
}

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

export interface IFinancialSpreadingSummaryLean extends IFinancialSpreadingSummary {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

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

export type IFinancialSpreadingSummaryModel = Model<IFinancialSpreadingSummary>;

export const FinancialSpreadingSummarySchema = new mongoose.Schema<IFinancialSpreadingSummary, IFinancialSpreadingSummaryModel>(
  {
    borrowerId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.borrowers,
      required: true,
    },
    rawData: {
      type: mongoose.Schema.Types.Mixed,
    },
    summary: {
      type: String,
    },
  },
  {
    timestamps: { createdAt: true, updatedAt: true },
  },
);

export const FinancialSpreadingSummary = mongoose.model<IFinancialSpreadingSummary, IFinancialSpreadingSummaryModel>(MODEL_NAMES.financialSpreadingSummary, FinancialSpreadingSummarySchema);
