import { useQuery } from '@tanstack/react-query'
import { getUserPermisos } from '../api/getUserPermisos'
import type { UsuarioPermisos } from '../types'
import type { UseQueryResult } from '@tanstack/react-query'

export const userPermisosQueryKey = (id: number) => ['users', id, 'permisos'] as const

export function useUserPermisos(id: number): UseQueryResult<UsuarioPermisos> {
  return useQuery({
    queryKey: userPermisosQueryKey(id),
    queryFn: () => getUserPermisos(id),
    staleTime: 15_000,
    enabled: id > 0,
  })
}
