import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';

export type MonthlySummaryDocument = HydratedDocument<MonthlySummary>;

@Schema({ timestamps: false, collection: 'monthly_summaries' })
export class MonthlySummary {
  @Prop({ required: true, index: true })
  userId: string;

  @Prop({ required: true, index: true })
  year: number;

  @Prop({ required: true })
  month: number;

  @Prop({ default: 0 })
  totalDistance: number;

  @Prop({ default: 0 })
  travelTime: number;

  @Prop({ default: 0 })
  meetingTime: number;

  @Prop({ default: 0 })
  idleTime: number;

  @Prop({ default: 0 })
  tripsCompleted: number;

  @Prop()
  productivityScore?: number;
}

export const MonthlySummarySchema = SchemaFactory.createForClass(MonthlySummary);
MonthlySummarySchema.index({ userId: 1, year: 1, month: 1 }, { unique: true });
