import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';
import { LeadType, PunchType } from '../../common/constants/enums';

export type PunchDocument = HydratedDocument<Punch>;

@Schema({ timestamps: { createdAt: true, updatedAt: false }, collection: 'punches' })
export class Punch {
  @Prop({ required: true, index: true })
  tripId: string;

  @Prop({ type: String, enum: PunchType, required: true })
  type: PunchType;

  @Prop({ required: true })
  timestamp: Date;

  @Prop({ required: true })
  latitude: number;

  @Prop({ required: true })
  longitude: number;

  @Prop()
  address?: string;

  @Prop()
  batteryPercent?: number;

  @Prop()
  gpsAccuracy?: number;

  @Prop()
  speed?: number;

  @Prop({ default: false })
  isMockLocation: boolean;

  @Prop()
  meetingSummary?: string;

  @Prop({ type: String, enum: LeadType })
  leadType?: LeadType;

  @Prop()
  customerNotes?: string;
}

export const PunchSchema = SchemaFactory.createForClass(Punch);
PunchSchema.index({ tripId: 1, type: 1 });
PunchSchema.index({ tripId: 1, timestamp: 1 });
