import api from '../config/api';
import { LocationLog } from '../types';

export const locationService = {
  async save(data: {
    latitude: number;
    longitude: number;
    accuracy?: number;
    altitude?: number;
    speed?: number;
    heading?: number;
    battery_level?: number;
    job_id?: number;
    device_id?: string;
  }): Promise<any> {
    const response = await api.post('/location', data);
    return response.data;
  },

  async history(userId?: number): Promise<LocationLog[]> {
    const url = userId ? `/location/history/${userId}` : '/location/history';
    const response = await api.get(url);
    return response.data.data || response.data.locations || response.data || [];
  },
};
