import { useQuery, useMutation } from '@tanstack/react-query'
import { inquiryReportService } from '../services/inquiryReportService'
import type { InquiryPreparationReportDraft } from '../domain/inquiryReport'

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

export function useCreateInquiryReport() {
  return useMutation({
    mutationFn: ({
      inquiryId,
      selectedPropertyIds,
    }: {
      inquiryId: string
      selectedPropertyIds: string[]
    }) => inquiryReportService.create(inquiryId, selectedPropertyIds),
  })
}

export function useUpdateInquiryReport() {
  return useMutation({
    mutationFn: ({
      draftId,
      data,
    }: {
      draftId: string
      data: Partial<InquiryPreparationReportDraft>
    }) => inquiryReportService.update(draftId, data),
  })
}

export function useFinalizeInquiryReport() {
  return useMutation({
    mutationFn: (draftId: string) => inquiryReportService.finalize(draftId),
  })
}
