import { axiosClient } from '@/api/axiosClient'
import type { PagedResult, UserListItem, UsuariosQuery } from '../types'

export async function listUsers(query: UsuariosQuery): Promise<PagedResult<UserListItem>> {
  const params = new URLSearchParams()

  if (query.page !== undefined) params.set('page', String(query.page))
  if (query.pageSize !== undefined) params.set('pageSize', String(query.pageSize))
  if (query.rol !== undefined && query.rol !== '') params.set('rol', query.rol)
  if (query.activo !== undefined) params.set('activo', String(query.activo))
  if (query.search !== undefined && query.search !== '') params.set('search', query.search)

  const response = await axiosClient.get<PagedResult<UserListItem>>('/api/v1/users', { params })
  return response.data
}
