import { type LonLatPoint } from '../../utils/projection'
import { type GameSessionStatus } from '../core/gameSessionState'

export type DevicePose = 'upright' | 'tilted' | 'flat'
export type HeadingConfidence = 'low' | 'medium' | 'high'

export interface TelemetryState {
  sessionStatus: GameSessionStatus
  sessionStartedAt: number | null
  sessionEndedAt: number | null
  elapsedMs: number
  distanceMeters: number
  currentSpeedKmh: number | null
  averageSpeedKmh: number | null
  distanceToTargetMeters: number | null
  targetControlId: string | null
  targetPoint: LonLatPoint | null
  lastGpsPoint: LonLatPoint | null
  lastGpsAt: number | null
  lastGpsAccuracyMeters: number | null
  accelerometer: { x: number; y: number; z: number } | null
  accelerometerUpdatedAt: number | null
  accelerometerSampleCount: number
  gyroscope: { x: number; y: number; z: number } | null
  deviceMotion: { alpha: number | null; beta: number | null; gamma: number | null } | null
  deviceHeadingDeg: number | null
  devicePose: DevicePose
  headingConfidence: HeadingConfidence
  heartRateBpm: number | null
  caloriesKcal: number | null
  calorieTrackingAt: number | null
}

export const EMPTY_TELEMETRY_STATE: TelemetryState = {
  sessionStatus: 'idle',
  sessionStartedAt: null,
  sessionEndedAt: null,
  elapsedMs: 0,
  distanceMeters: 0,
  currentSpeedKmh: null,
  averageSpeedKmh: null,
  distanceToTargetMeters: null,
  targetControlId: null,
  targetPoint: null,
  lastGpsPoint: null,
  lastGpsAt: null,
  lastGpsAccuracyMeters: null,
  accelerometer: null,
  accelerometerUpdatedAt: null,
  accelerometerSampleCount: 0,
  gyroscope: null,
  deviceMotion: null,
  deviceHeadingDeg: null,
  devicePose: 'upright',
  headingConfidence: 'low',
  heartRateBpm: null,
  caloriesKcal: null,
  calorieTrackingAt: null,
}
