import { apiClient } from './apiClient'

export interface TelemetryData {
    latitude: number
    longitude: number
    speed?: number
    heading?: number
    status?: 'active' | 'offline' | 'break'
}

export interface ActiveUnit {
    user_id: string
    full_name: string
    latitude: number
    longitude: number
    speed?: number
    heading?: number
    timestamp: string
    vehicle_type: string
    license_plate: string
}

export const telemetryService = {
    async sendTelemetry(data: TelemetryData) {
        return await apiClient.post('/api/telemetry', data)
    },

    async getActiveUnits(): Promise<ActiveUnit[]> {
        const response = await apiClient.get<ActiveUnit[]>('/api/telemetry/active')
        return response.data
    }
}
