import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';

export type GpsPointDocument = HydratedDocument<GpsPoint>;

@Schema({ timestamps: { createdAt: true, updatedAt: false }, collection: 'gps_points' })
export class GpsPoint {
  @Prop({ index: true })
  tripId?: string;

  @Prop({ required: true, index: true })
  userId: string;

  @Prop()
  clientPointId?: string;

  @Prop({ required: true })
  latitude: number;

  @Prop({ required: true })
  longitude: number;

  @Prop()
  accuracy?: number;

  @Prop()
  speed?: number;

  @Prop()
  bearing?: number;

  @Prop()
  batteryLevel?: number;

  @Prop({ required: true, index: true })
  timestamp: Date;

  @Prop({ default: false })
  isSmoothed: boolean;

  @Prop({ index: true })
  legId?: string;

  @Prop()
  sessionId?: string;

  @Prop()
  source?: string;
}

export const GpsPointSchema = SchemaFactory.createForClass(GpsPoint);
GpsPointSchema.index({ tripId: 1, clientPointId: 1 }, { unique: true, sparse: true });
GpsPointSchema.index({ tripId: 1, timestamp: 1 });
