import mongoose, { Document } from 'mongoose';

import { MODEL_NAMES } from './_models';

interface IDateFields {
  createdAt: Date;
  updatedAt: Date;
}

export interface ILoanTransactionFile {
  userUploaded?: string;
  transactionsId: mongoose.Types.ObjectId[];
  statementIds: mongoose.Types.ObjectId[];
  fileName: string;
  sheetName: string;
  effectiveDate: string;
}

export interface ILoanTransactionFileDoc extends ILoanTransactionFile, Document, IDateFields {
}

export const LoanTransactionFileSchema = new mongoose.Schema(
  {
    userUploaded: {
      type: String,
      trim: true,
    },
    transactionsId: {
      type: [mongoose.Schema.Types.ObjectId],
      ref: MODEL_NAMES.loanTransactions,
      required: true,
    },
    statementIds: {
      type: [mongoose.Schema.Types.ObjectId],
      ref: MODEL_NAMES.loanStatements,
      required: true,
    },
    fileName: {
      type: String,
      trim: true,
      required: true,
    },
    sheetName: {
      type: String,
      trim: true,
      required: true,
    },
    effectiveDate: {
      type: String,
      required: true,
      trim: true,
    },
    __v: {
      type: Number,
      select: false,
    },
  },
  { timestamps: true },
);

export const LoanTransactionFileModel: mongoose.Model<ILoanTransactionFileDoc> = mongoose.model<ILoanTransactionFileDoc>(MODEL_NAMES.loanTransactionsFiles, LoanTransactionFileSchema);
