import mongoose, { Document } from 'mongoose';

import { MODEL_NAMES } from './_models';

export interface IInventoryManualEntryItem {
  inventoryName: string;
  totalQty: number;
  totalValue: number;
  ineligible: number;
  advanceRate: number;
  availability: number;
}

export interface IInventoryManualEntryItemDoc extends IInventoryManualEntryItem, Document {
}

export interface IInventoryManualEntry {
  bbcDateId: string;
  items: IInventoryManualEntryItem[];
}

export interface IInventoryManualEntryDoc extends IInventoryManualEntry, Document {
  items: IInventoryManualEntryItemDoc[];
}

export const InventoryManualEntrySchema = new mongoose.Schema(
  {
    bbcDateId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: MODEL_NAMES.BBCDates,
      required: true,
    },
    items: [{
      inventoryName: {
        type: String,
        required: true,
      },
      totalQty: {
        type: Number,
        required: true,
      },
      totalValue: {
        type: Number,
        required: true,
      },
      ineligible: {
        type: Number,
        required: true,
      },
      advanceRate: {
        type: Number,
        required: true,
      },
      availability: {
        type: Number,
        required: true,
      }
    }],
    __v: { type: Number, select: false },
  },
  { timestamps: true },
);

export const InventoryManualEntryModel: mongoose.Model<IInventoryManualEntryDoc> = mongoose.model<IInventoryManualEntryDoc>(MODEL_NAMES.inventoryManualEntries, InventoryManualEntrySchema);
