import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/ReceiptService";
import { CreateReceiptType } from "../types/ReceiptTypes";

export const useGetInvoices = (
  status: string,
  customerId: string,
  search: string,
  date: string,
  endDate: string,
  page: number
) => {
  return useQuery({
    queryKey: ["invoices", status, customerId, search, date, endDate, page],
    queryFn: () =>
      api.getInvoces(status, customerId, search, date, endDate, page),
  });
};

export const useCreateInvoice = () => {
  return useMutation({
    mutationFn: (variables: CreateReceiptType) => api.createInvoice(variables),
  });
};

export const useGetInvoiceById = (id: string) => {
  return useQuery({
    queryKey: ["invoice", id],
    queryFn: () => api.getInvoiceById(id),
  });
};

export const useUpdateInvoice = () => {
  return useMutation({
    mutationFn: ({ id, params }: { id: string; params: CreateReceiptType }) =>
      api.updateInvoice(id, params),
  });
};

export const useDeleteInvoice = () => {
  return useMutation({
    mutationFn: api.deleteInvoice,
  });
};
