import { apiClient } from '@/lib/api-client';
import { Booking, BookingFilters } from '@/types';
import { PaginatedResponse } from '@edr/types';

export const bookingsApi = {
  getAll: (filters?: BookingFilters) => {
    const params = new URLSearchParams();
    if (filters?.status) params.append('status', filters.status);
    if (filters?.dateFrom) params.append('dateFrom', filters.dateFrom);
    if (filters?.dateTo) params.append('dateTo', filters.dateTo);
    if (filters?.search) params.append('search', filters.search);
    if (filters?.page) params.append('page', filters.page.toString());
    if (filters?.pageSize) params.append('pageSize', filters.pageSize.toString());
    
    return apiClient.get<PaginatedResponse<Booking>>(`/bookings?${params.toString()}`);
  },

  getById: (id: string) => {
    return apiClient.get<Booking>(`/bookings/${id}`);
  },

  updateStatus: (id: string, status: string) => {
    return apiClient.patch<Booking>(`/bookings/${id}/status`, { status });
  },

  cancel: (id: string, reason?: string) => {
    return apiClient.post<Booking>(`/bookings/${id}/cancel`, { reason });
  },
};
