import { BaseEntity } from "@edr/api-common";
import { Column, Entity, Index } from "typeorm";

/** One GPS fix from a tracker (append-only history). Same table as freight-api. */
@Entity({ name: "gps_positions", schema: "freight" })
@Index(["deviceId", "gpsTime"])
@Index(["vehicleId", "gpsTime"])
export class GpsPosition extends BaseEntity {
  @Column({ name: "device_id", type: "uuid" })
  deviceId!: string;

  @Column({ name: "imei", type: "varchar", length: 20 })
  imei!: string;

  @Column({ name: "vehicle_id", type: "uuid", nullable: true })
  vehicleId?: string | null;

  @Column({ name: "lat", type: "numeric", precision: 10, scale: 6 })
  lat!: number;

  @Column({ name: "lng", type: "numeric", precision: 10, scale: 6 })
  lng!: number;

  @Column({ name: "speed", type: "numeric", precision: 6, scale: 2, default: 0 })
  speed!: number;

  @Column({ name: "course", type: "int", default: 0 })
  course!: number;

  @Column({ name: "satellites", type: "int", default: 0 })
  satellites!: number;

  @Column({ name: "positioned", type: "boolean", default: false })
  positioned!: boolean;

  @Column({ name: "gps_time", type: "timestamptz" })
  gpsTime!: Date;

  @Column({ name: "alarm", type: "int", default: 0 })
  alarm!: number;
}
