import { useMutation, useQuery } from '@tanstack/react-query'
import { aiService, parseListingText } from '../services/aiService'
import type { OfferEmailPayload, FitOutAdviceInput, PreMarketRentInput } from '../services/aiService'

export function useParseNeed() {
  return useMutation({
    mutationFn: (text: string) => aiService.parseNeed(text),
  })
}

export function useGenerateOfferEmail() {
  return useMutation({
    mutationFn: (payload: OfferEmailPayload) => aiService.generateOfferEmail(payload),
  })
}

export function useGenerateDecisionBrief() {
  return useMutation({
    mutationFn: (shortlistId: string) => aiService.generateDecisionBrief(shortlistId),
  })
}

export function useParseListingText() {
  return useMutation({
    mutationFn: (text: string) => parseListingText(text),
  })
}

export function useFitOutAdvice(input: FitOutAdviceInput | null) {
  return useQuery({
    queryKey: ['fitOutAdvice', input],
    queryFn: () => aiService.generateFitOutAdvice(input!),
    enabled: !!input,
    staleTime: Infinity,
  })
}

export function usePreMarketRentRecommendation(input: PreMarketRentInput | null) {
  return useQuery({
    queryKey: ['preMarketRent', input],
    queryFn: () => aiService.recommendPreMarketRent(input!),
    enabled: !!input && !!input.city,
    staleTime: Infinity,
  })
}
