import { useQuery, useMutation } from '@tanstack/react-query'
import { offerReportService } from '../services/offerReportService'
import type { OfferReportDraft } from '../domain/offerReport'

export function useOfferReportByInquiry(inquiryId: string | null) {
  return useQuery({
    queryKey: ['offer-report', inquiryId],
    queryFn: () => offerReportService.getByInquiry(inquiryId!),
    enabled: !!inquiryId,
  })
}

export function useCreateOfferReport() {
  return useMutation({
    mutationFn: ({
      inquiryId,
      propertyId,
      tenantName,
      propertyTitle,
    }: {
      inquiryId: string
      propertyId: string
      tenantName?: string
      propertyTitle?: string
    }) => offerReportService.create(inquiryId, propertyId, tenantName, propertyTitle),
  })
}

export function useUpdateOfferReport() {
  return useMutation({
    mutationFn: ({ draftId, data }: { draftId: string; data: Partial<OfferReportDraft> }) =>
      offerReportService.update(draftId, data),
  })
}

export function useGenerateOfferReportPdf() {
  return useMutation({
    mutationFn: (draftId: string) => offerReportService.generatePdf(draftId),
  })
}
