import mongoose, { Document } from 'mongoose';
import { MODEL_NAMES } from './_models';

export interface IBorrowerDataOption {
  order: number;
  name: string;
  type: string;
  isActive: boolean;
}

interface IBorrowerDataOptionDoc extends IBorrowerDataOption, Document {
}

export const BorrowerDataOptionSchema = new mongoose.Schema(
  {
    order: {
      type: Number,
      required: true,
    },
    name: {
      type: String,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
    isActive: {
      type: Boolean,
    },
  },
  { timestamps: false, versionKey: false },
);

export const BorrowerDataOptionModel: mongoose.Model<IBorrowerDataOptionDoc> = mongoose.model<IBorrowerDataOptionDoc>(MODEL_NAMES.borrowerDataOptions, BorrowerDataOptionSchema);

export interface IBorrowerData {
  dataOption: mongoose.Types.ObjectId,
  dataValue: boolean | string
}

export interface IBorrowerDataDoc extends IBorrowerData, Document {
}

export interface IBorrowerDataDocWithName extends IBorrowerDataDoc {
  dataName: string;
}

export const BorrowerDataSchema = new mongoose.Schema(
  {
    dataOption: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.borrowerDataOptions,
      required: true,
    },
    dataValue: {
      type: mongoose.Schema.Types.Mixed,
      required: true,
    },
  },
  { timestamps: false, versionKey: false },
);

export const BorrowerDataModel: mongoose.Model<IBorrowerDataDoc> = mongoose.model<IBorrowerDataDoc>(MODEL_NAMES.borrowerData, BorrowerDataSchema);
