import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Document, Types } from "mongoose";

export type InventoryBalanceDocument = InventoryBalance & Document;

@Schema({ collection: "inventory_balances", timestamps: false })
export class InventoryBalance {
  @Prop({ type: Types.ObjectId, ref: "Warehouse", required: true })
  declare warehouseId: Types.ObjectId;

  @Prop({ type: Types.ObjectId, ref: "Item", required: true })
  declare itemId: Types.ObjectId;

  @Prop({ type: Types.ObjectId, ref: "Batch", required: true })
  declare batchId: Types.ObjectId;

  @Prop({ required: true, default: 0 })
  declare currentQuantityMt: number;

  @Prop({ required: true, default: 26000 })
  declare thresholdTargetMt: number;

  @Prop({ required: true })
  declare lastUpdated: string;
}

export const InventoryBalanceSchema = SchemaFactory.createForClass(InventoryBalance);

InventoryBalanceSchema.index({ batchId: 1 }, { unique: true });
