import { fetchApi } from './client';
import type { User } from './types';

export const usersApi = {
  getAll: (role?: string) => {
    const query = role ? `?role=${role}` : '';
    return fetchApi<{ users: User[] }>(`/api/users${query}`);
  },

  getById: (id: string) => fetchApi<{ user: User }>(`/api/users/${id}`),

  update: (id: string, data: Partial<User>) =>
    fetchApi<{ user: User }>(`/api/users/${id}`, {
      method: 'PUT',
      body: JSON.stringify(data),
    }),

  delete: (id: string) =>
    fetchApi<{ message: string }>(`/api/users/${id}`, { method: 'DELETE' }),
};
