import axios from "../../../config/axios";
import { CreateReceiptType } from "../types/ReceiptTypes";

export const getInvoces = async (
  status: string,
  customerId: string,
  search: string,
  date: string,
  endDate: string,
  page: number
) => {
  const params = new URLSearchParams();
  if (status) params.append("status", status);
  if (customerId) params.append("userId", customerId);
  if (search) params.append("q", search);
  if (date) params.append("since", date);
  if (endDate) params.append("to", endDate);
  if (page) params.append("page", page.toString());
  const query = params.toString();
  const { data } = await axios.get(`/invoices?${query}`);
  return data;
};

export const createInvoice = async (params: CreateReceiptType) => {
  const { data } = await axios.post(`/invoices`, params);
  return data;
};

export const getInvoiceById = async (id: string) => {
  const { data } = await axios.get(`/invoices/${id}`);
  return data;
};

export const updateInvoice = async (id: string, params: CreateReceiptType) => {
  const { data } = await axios.patch(`/invoices/${id}`, params);
  return data;
};

export const deleteInvoice = async (id: string) => {
  const { data } = await axios.delete(`/invoices/${id}`);
  return data;
};
