import mongoose, { Document } from 'mongoose';

import { MODEL_NAMES } from './_models';
import { IEmailRecipient } from './ComplianceItem.model';

const mongooseLeanId = require('../plugins/id.plugin');

export interface IFinancialComplianceSettings {
  invoiceSentDate: Date;
  dueDate: Date;
  stopFundingDate: Date;
  managementEmails?: IEmailRecipient[];
  financialEmails?: IEmailRecipient[];
}

export interface IFinancialComplianceSettingsDocument extends IFinancialComplianceSettings, Document {
}

export const FinancialComplianceSettingsSchema = new mongoose.Schema(
  {
    isDeleted: {
      type: Boolean,
      default: false
    },
    invoiceSentDate: {
      type: Date,
      required: false,
      default: null,
    },
    dueDate: {
      type: Date,
      required: false,
      default: null,
    },
    stopFundingDate: {
      type: Date,
      required: false,
      default: null,
    },
    managementEmails: [{
      email: {
        type: String,
        trim: true,
        required: false,
      },
      title: {
        type: String,
        trim: true,
        required: false,
      },
      isActive: {
        type: Boolean,
        required: false,
      }
    }],
    financialEmails: [{
      email: {
        type: String,
        trim: true,
        required: false,
      },
      title: {
        type: String,
        trim: true,
        required: false,
      },
      isActive: {
        type: Boolean,
        required: false,
      }
    }],
    __v: { type: Number, select: false },
  }
);

FinancialComplianceSettingsSchema.plugin(mongooseLeanId);

export default mongoose.model<IFinancialComplianceSettingsDocument>(MODEL_NAMES.financialComplianceSettings, FinancialComplianceSettingsSchema);
