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

export type ItemDocument = Item & Document;

@Schema({ collection: "items", timestamps: true })
export class Item {
  @Prop({ required: true, unique: true })
  declare itemCode: string;

  /** Mapped from 'description' field in the real collection */
  @Prop({ type: String, default: null })
  declare itemName: string | null;

  /** The human-readable description, e.g. "Rice - Najm Suhail - 2 Kg" */
  @Prop({ type: String, default: null })
  declare description: string | null;

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

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

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

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

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

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

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

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

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

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

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

  /** Weight per bag in kg, e.g. 25, 40, 2 */
  @Prop({ type: Number, default: null })
  declare bagWeightKg: number | null;

  // Strategic stock sheet descriptor fields
  @Prop({ type: String, default: null })
  declare blend: string | null;

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

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

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

  /** Unit of measure string, e.g. "BAG/1x40kg" — computed from bagWeightKg if not set */
  @Prop({ type: String, default: null })
  declare unit: string | null;
}

export const ItemSchema = SchemaFactory.createForClass(Item);
