import Http from "../utils/http";
import { host } from "../utils/constant";

const indexHttp = new Http(host);

export function fetchContact() {
  return indexHttp.get("/common/contact");
}

export function fetchCommonQuestions() {
  return indexHttp.get("/qa");
}

export interface ApplyInvoiceParams {
  startChargeSeqs: string[];
  email?: string;
  phone?: string;
  invoiceType?: string;
  invoiceTitle?: string;
  taxId?: string;
  address?: string;
  bankName?: string;
  bankAccount?: string;
  remark?: string;
}

export function applyInvoice(params: ApplyInvoiceParams) {
  return indexHttp.post("/invoice/applyInvoice", { data: params });
}

export function fetchHomeBanner() {
  return indexHttp.get("/banner");
}

export function fetchInvoiceList() {
  return indexHttp.get("/invoice/list?status=1");
}

export function cancelApplyInvoice() {
  return indexHttp.get("/invoice/cancelApplyInvoice");
}

export function fetchInvoicePDF(invoiceId: string) {
  return indexHttp.get(`/invoice/downloadInvoice/${invoiceId}`);
}

// ==================== 发票抬头管理 ====================

export function fetchTitleList() {
  return indexHttp.get("/invoice/title/list");
}

export function createTitle(data: any) {
  return indexHttp.post("/invoice/title", { data });
}

export function updateTitle(id: number, data: any) {
  return indexHttp.put(`/invoice/title/${id}`, { data });
}

export function deleteTitle(id: number) {
  return indexHttp.post(`/invoice/title/${id}/delete`);
}

export function setDefaultTitle(id: number) {
  return indexHttp.put(`/invoice/title/${id}/default`);
}
