import apis from '../utils/request';
const { GET, POST, PUT, DELETE } = apis

// 获取当前商户开票信息
export const getInvoiceInfo = async function() {
  return await GET(`/wx/getInvoiceInfo/${wx.getStorageSync('tenement').id}`);
}

// 创建开票信息
export const createInvoiceInfo = async function(data) {
  return await POST(`/wx/createInvoiceInfo`, data);
}

// 修改开票信息
export const updateInvoiceInfo = async function(data) {
  return await PUT(`/wx/updateInvoiceInfo`, data);
}

// 删除发票信息
export const deleteInvoiceInfo = async function(id) {
  return await DELETE(`/wx/deleteInvoiceInfo/${id}`);
}

// 获取可开发票列表
export const getInvoiceList = async function() {
  const tenement = wx.getStorageSync('tenement');
  return await GET(`/wx/getInvoiceList?tenement=${tenement?.id}`);
}

// 获取创建的发开票信息详情
export const getInvoiceInfoDetail = async function(id) {
  return await GET(`/wx/getInvoiceInfoDetail/${id}/${wx.getStorageSync('tenement')?.id}`);
}

// 获取已开发票的列表
export const getAlreadyInvoiceList = async function(page) {
  return await GET(`/wx/getAlreadyInvoiceList?tenement=${wx.getStorageSync('tenement')?.id}&page=${page}`);
}

// 开票
export const makeInvoice = async function(data) {
  return await POST(`/wx/invoice`, data);
}

// 下载发票文件
export const downloadInvoice = async function(id, type) {
  return await GET(`/wx/downloadInvoice/${id}?type=${type}`,);
}