import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Document, Types } from "mongoose";
import { StockLocation } from "../enums/stock-location.enum";

// Defines the interface for your document
export type StockTransferLogDocument = StockTransfer & Document;

@Schema()
export class StockTransfer {
    @Prop({
        type: Types.ObjectId,
        ref: "Product",
        required: true,
        unique: true,
    })
    productId: Types.ObjectId;

    @Prop({
        type: String,
        enum: Object.values(StockLocation).filter((value) => typeof value === "string"),
    })
    from: StockLocation;

    @Prop({
        type: String,
        enum: Object.values(StockLocation).filter((value) => typeof value === "string"),
    })
    to: StockLocation;

    @Prop({ required: true })
    quantity: number;

    @Prop({ default: Date.now })
    transferredAt: Date;
}

// Generates the actual Mongoose Schema
export const StockTransferLogSchema = SchemaFactory.createForClass(StockTransfer);
