import axios from "../../../config/axios";
import {
  ApplyDiscountType,
  ApproveInvoiceType,
  RequestApproveInvoiceType,
} from "../types/ReceiptTypes";

export const getInvoice = async (status: string) => {
  const { data } = await axios.get(`/invoices/user?status=${status}`);
  return data;
};

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

export const requestApprove = async (params: RequestApproveInvoiceType) => {
  const { data } = await axios.post(
    `/invoices/${params.id}/approve/request`,
    params
  );
  return data;
};

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

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

export const applyDiscount = async (params: ApplyDiscountType) => {
  const { data } = await axios.post(
    `/invoices/${params.id}/apply-discount`,
    params
  );
  return data;
};

export const removeDiscount = async (id: string) => {
  const { data } = await axios.post(`/invoices/${id}/cancel-discount`);
  return data;
};
