import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { marktHinweisService } from '../services/marktHinweisService'
import type { CreateMarktHinweisInput } from '../domain/marktHinweis'

export function useMarktHinweise() {
  return useQuery({
    queryKey: ['marktHinweise'],
    queryFn: () => marktHinweisService.getAll(),
    staleTime: 60_000,
  })
}

export function useCreateMarktHinweis() {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: (data: CreateMarktHinweisInput) => marktHinweisService.create(data),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['marktHinweise'] })
    },
  })
}
