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

export const passengersApi = {
  getAll: (filters?: PassengerFilters) => {
    const params = new URLSearchParams();
    if (filters?.search) params.append('search', filters.search);
    if (filters?.verified !== undefined) params.append('verified', filters.verified.toString());
    if (filters?.role) params.append('role', filters.role);
    if (filters?.page) params.append('page', filters.page.toString());
    if (filters?.pageSize) params.append('pageSize', filters.pageSize.toString());
    if ((filters as any)?.gender) params.append('gender', (filters as any).gender);
    if ((filters as any)?.nationality) params.append('nationality', (filters as any).nationality);
    if ((filters as any)?.dateFrom) params.append('dateFrom', (filters as any).dateFrom);
    if ((filters as any)?.dateTo) params.append('dateTo', (filters as any).dateTo);
    return apiClient.get<PaginatedResponse<Passenger.IPassenger>>(`/passengers?${params.toString()}`);
  },

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

  update: (id: string, data: Partial<Passenger.IPassenger>) => {
    return apiClient.patch<Passenger.IPassenger>(`/passengers/${id}`, data);
  },

  delete: (id: string, cascade = false) => {
    return apiClient.delete(`/passengers/${id}${cascade ? '?cascade=true' : ''}`);
  },
};
