import type { Client, PaginatedResponse, ClientSearchParams } from '../types/client';
import { api } from './api';

export const clientsService = {
  async getClients(params?: ClientSearchParams): Promise<PaginatedResponse<Client>> {
    const response = await api.get<{ data: Client[]; nextCursor: string | null; hasMore: boolean }>('/clients', {
      params: {
        search: params?.query,
        cursor: params?.cursor,
        limit: params?.limit,
        assignedTrainerId: params?.assignedTrainerId,
      },
    });
    return {
      data: response.data,
      cursor: response.nextCursor,
      hasMore: response.hasMore,
      total: response.data.length,
    };
  },

  async getClient(id: string): Promise<Client> {
    return api.get<Client>(`/clients/${id}`);
  },

  async searchClients(query: string): Promise<Client[]> {
    const response = await api.get<{ data: Client[]; nextCursor: string | null; hasMore: boolean }>('/clients', {
      params: { search: query, limit: 20 },
    });
    return response.data;
  },
};
