/**
 * @ai-summary API calls for ownership-costs feature
 */

import { apiClient } from '../../../core/api/client';
import {
  OwnershipCost,
  CreateOwnershipCostRequest,
  UpdateOwnershipCostRequest,
  OwnershipCostStats
} from '../types/ownership-costs.types';

export const ownershipCostsApi = {
  /**
   * Get all ownership costs for a vehicle
   */
  getByVehicle: async (vehicleId: string): Promise<OwnershipCost[]> => {
    const response = await apiClient.get(`/ownership-costs/vehicle/${vehicleId}`);
    return response.data;
  },

  /**
   * Get a single ownership cost by ID
   */
  getById: async (id: string): Promise<OwnershipCost> => {
    const response = await apiClient.get(`/ownership-costs/${id}`);
    return response.data;
  },

  /**
   * Create a new ownership cost
   */
  create: async (data: CreateOwnershipCostRequest): Promise<OwnershipCost> => {
    const response = await apiClient.post('/ownership-costs', data);
    return response.data;
  },

  /**
   * Update an existing ownership cost
   */
  update: async (id: string, data: UpdateOwnershipCostRequest): Promise<OwnershipCost> => {
    const response = await apiClient.put(`/ownership-costs/${id}`, data);
    return response.data;
  },

  /**
   * Delete an ownership cost
   */
  delete: async (id: string): Promise<void> => {
    await apiClient.delete(`/ownership-costs/${id}`);
  },

  /**
   * Get aggregated cost stats for a vehicle
   */
  getVehicleStats: async (vehicleId: string): Promise<OwnershipCostStats> => {
    const response = await apiClient.get(`/ownership-costs/vehicle/${vehicleId}/stats`);
    return response.data;
  },
};
