import { useQuery } from '@tanstack/react-query'
import { latentNeedService } from '../services/latentNeedService'
import type { LatentNeedFilters } from '../provider/ILatentNeedProvider'

export function usePublicNeeds(filters?: LatentNeedFilters) {
  return useQuery({
    queryKey: ['latent-needs', filters ?? {}],
    queryFn: () => latentNeedService.getPublicNeeds(filters),
    select: (res) => res.data ?? [],
  })
}

export function useLatentNeedById(id: string | null) {
  return useQuery({
    queryKey: ['latent-need', id],
    queryFn: () => latentNeedService.getNeedById(id!),
    enabled: !!id,
    select: (res) => res.data ?? null,
  })
}
