import { apiClient } from '../../../core/api/client';
import type { CheckoutRequest, PaymentMethodUpdateRequest, DowngradeRequest, NeedsVehicleSelectionResponse } from '../types/subscription.types';

export const subscriptionApi = {
  getSubscription: () => apiClient.get('/subscriptions'),
  needsVehicleSelection: async (): Promise<NeedsVehicleSelectionResponse> => {
    const response = await apiClient.get<NeedsVehicleSelectionResponse>('/subscriptions/needs-vehicle-selection');
    return response.data;
  },
  checkout: (data: CheckoutRequest) => apiClient.post('/subscriptions/checkout', data),
  cancel: () => apiClient.post('/subscriptions/cancel'),
  reactivate: () => apiClient.post('/subscriptions/reactivate'),
  updatePaymentMethod: (data: PaymentMethodUpdateRequest) => apiClient.put('/subscriptions/payment-method', data),
  getInvoices: () => apiClient.get('/subscriptions/invoices'),
  downgrade: (data: DowngradeRequest) => apiClient.post('/subscriptions/downgrade', data),
  createDonation: (amount: number) => apiClient.post('/donations', { amount }),
  getDonations: () => apiClient.get('/donations'),
};
