import { useMutation } from '@tanstack/react-query'
import { offerService } from '../services/offerService'
import type { AssetType } from '../domain/enums'

export function useCreateOfferDraft() {
  return useMutation({
    mutationFn: (input: {
      needId: string
      selectedPropertyIds: string[]
      needTitle: string
      location: string
      assetType: AssetType
      sizeRange: { min: number; max: number }
    }) =>
      offerService.createOfferDraft(
        input.needId,
        input.selectedPropertyIds,
        input.needTitle,
        input.location,
        input.assetType,
        input.sizeRange,
      ),
  })
}

export function useUpdateOfferField() {
  return useMutation({
    mutationFn: (input: { offerDraftId: string; fieldId: string; value: string }) =>
      offerService.updateOfferField(input.offerDraftId, input.fieldId, input.value),
  })
}

export function useMarkOfferChecked() {
  return useMutation({
    mutationFn: (offerDraftId: string) => offerService.markOfferChecked(offerDraftId),
  })
}

export function useGeneratePdfPreview() {
  return useMutation({
    mutationFn: (offerDraftId: string) => offerService.generatePdfPreview(offerDraftId),
  })
}

export function useSendOffer() {
  return useMutation({
    mutationFn: (offerDraftId: string) => offerService.sendOffer(offerDraftId),
  })
}
