import mongoose, { Model } from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface IBorrowerNoteSubject {
  name: string,
  order: number,
}

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

export interface IBorrowerNoteSubjectLean extends IBorrowerNoteSubject {
  _id: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

export interface IBorrowerNoteSubjectPlain extends IBorrowerNoteSubject {
  _id: string;
  createdAt: Date;
  updatedAt: Date;
}

export type BorrowerNoteSubjectModel = Model<IBorrowerNoteSubjectDoc>;

const BorrowerNoteAttachmentSchema = new mongoose.Schema<IBorrowerNoteSubject>({
  name: {
    type: String,
    required: true,
  },
});

export const BorrowerNoteSubjectSchema = new mongoose.Schema<IBorrowerNoteSubjectDoc>({
  name: {
    type: String,
    required: true,
  },
  order: {
    type: Number,
    required: true,
  },
}, {
  timestamps: true,
  versionKey: false,
});

export const BorrowerNoteSubject = mongoose.model<IBorrowerNoteSubjectDoc>(MODEL_NAMES.borrowerNoteSubject, BorrowerNoteSubjectSchema);
