import { apiClient } from '../../../core/api/client';
import { CreateFuelLogRequest, UpdateFuelLogRequest, FuelLogResponse, EnhancedFuelStats, FuelType, FuelGradeOption } from '../types/fuel-logs.types';

export const fuelLogsApi = {
  async create(data: CreateFuelLogRequest): Promise<FuelLogResponse> {
    const res = await apiClient.post('/fuel-logs', data);
    return res.data;
  },

  async getUserFuelLogs(): Promise<FuelLogResponse[]> {
    const res = await apiClient.get('/fuel-logs');
    return res.data;
  },

  async getFuelLogsByVehicle(vehicleId: string): Promise<FuelLogResponse[]> {
    const res = await apiClient.get(`/fuel-logs/vehicle/${vehicleId}`);
    return res.data;
  },

  async getVehicleStats(vehicleId: string): Promise<EnhancedFuelStats> {
    const res = await apiClient.get(`/fuel-logs/vehicle/${vehicleId}/stats`);
    return res.data;
  },

  async getFuelTypes(): Promise<{ value: FuelType; label: string; grades: FuelGradeOption[] }[]> {
    const res = await apiClient.get('/fuel-logs/fuel-types');
    return res.data.fuelTypes;
  },

  async getFuelGrades(fuelType: FuelType): Promise<FuelGradeOption[]> {
    const res = await apiClient.get(`/fuel-logs/fuel-grades/${fuelType}`);
    return res.data.grades;
  },

  async update(id: string, data: UpdateFuelLogRequest): Promise<FuelLogResponse> {
    const res = await apiClient.put(`/fuel-logs/${id}`, data);
    return res.data;
  },

  async delete(id: string): Promise<void> {
    await apiClient.delete(`/fuel-logs/${id}`);
  },

  async getById(id: string): Promise<FuelLogResponse> {
    const res = await apiClient.get(`/fuel-logs/${id}`);
    return res.data;
  }
};

