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

export type WeightLogDocument = WeightLog & Document;

@Schema({ timestamps: true, strict: true })
export class WeightLog {
  @Prop({
    type: Types.ObjectId,
    ref: "User",
    required: true,
  })
  userId: Types.ObjectId;

  @Prop({
    type: Number,
    required: true,
    min: 1,
  })
  weight: number;

  @Prop({
    type: Date,
    required: true,
  })
  recordedAt: Date;

  @Prop({ default: null })
  deleted_at: Date | null;
}

export const WeightLogSchema =
  SchemaFactory.createForClass(WeightLog);

// Helpful indexes
WeightLogSchema.index({
  userId: 1,
  recordedAt: -1,
});

WeightLogSchema.index({
  userId: 1,
  deleted_at: 1,
});