import mongoose, { Document } from 'mongoose';

import { ICollateralItem } from '../interfaces/collaterals.interface';
import { MODEL_NAMES } from './_models';

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

export const ACCOUNT_PAYABLE_FIELDS = [
  '_id',
  'apDate',
  'poNumber',
  'customerName',
  'amount',
  'otherInformation1',
  'otherInformation2',
  'otherInformation3',
];

export interface IAccountPayableItem extends ICollateralItem {
  bbcDate: Date;
  apDate: Date;
  poNumber: string;
  customerName: string;
  amount: number;
  otherInformation1: string;
  otherInformation2: string;
  otherInformation3: string;
}

export interface IAccountPayableItemDoc extends Document, IAccountPayableItem {
}

export const AccountPayableItemSchema = new mongoose.Schema(
  {
    bbcSheetId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.BBCSheets,
      required: true,
    },
    order: {
      type: Number,
      required: true,
    },
    apDate: {
      type: Date,
      required: true,
    },
    poNumber: {
      type: String,
      trim: true,
    },
    customerName: {
      type: String,
      trim: true,
    },
    amount: {
      type: Number,
      required: true,
    },
    otherInformation1: {
      type: String,
      trim: true,
    },
    otherInformation2: {
      type: String,
      trim: true,
    },
    otherInformation3: {
      type: String,
      trim: true,
    },
    __v: { type: Number, select: false },
  },
  { timestamps: true }
);

AccountPayableItemSchema.plugin(mongooseLeanId);

export const AccountPayableItemModel: mongoose.Model<IAccountPayableItemDoc> = mongoose.model<IAccountPayableItemDoc>('AccountPayableItem', AccountPayableItemSchema);
