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

export type InventoryThresholdStateDocument = InventoryThresholdState & Document;

@Schema({ collection: "inventory_threshold_states", timestamps: false })
export class InventoryThresholdState {
  @Prop({ required: true, unique: true })
  declare key: string;

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

  @Prop({ required: true, default: false })
  declare hasReachedThreshold: boolean;

  @Prop({ type: String, default: null })
  declare reachedAt: string | null;

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

export const InventoryThresholdStateSchema = SchemaFactory.createForClass(InventoryThresholdState);

InventoryThresholdStateSchema.index({ key: 1 }, { unique: true });
