import { http } from "@/utils/http";

type Result = {
  code: number;
  message: string;
  data?: any;
};

type ResultTable = {
  code: number;
  message: string;
  data?: {
    list: Array<any>;
    total: number;
    pageSize: number;
    currentPage: number;
  };
};

export const getNewProductApplyList = (params: {
  page?: number;
  pageSize?: number;
  productName?: string;
  barcode?: string;
  status?: number;
  applicantId?: number;
}) => {
  return http.request<ResultTable>("get", "/new-product-apply/list", { params });
};

export const getNewProductApplyById = (id: number) => {
  return http.request<Result>("get", `/new-product-apply/${id}`);
};

export const getNewProductApplyStatistics = () => {
  return http.request<Result>("get", "/new-product-apply/statistics");
};

export const submitNewProductApply = (data: any) => {
  return http.request<Result>("post", "/new-product-apply/submit", { data });
};

export const saveNewProductApplyDraft = (data: any) => {
  return http.request<Result>("post", "/new-product-apply/save-draft", { data });
};

export const updateNewProductApply = (id: number, data: any) => {
  return http.request<Result>("put", `/new-product-apply/${id}`, { data });
};

export const deleteNewProductApply = (id: number) => {
  return http.request<Result>("delete", `/new-product-apply/${id}`);
};

export const checkBarcode = (barcode: string) => {
  return http.request<Result>(
    "get",
    `/new-product-apply/check-barcode?barcode=${barcode}`
  );
};

// 主动刷新新品申请审核状态
export const refreshApplyStatus = (id: number) => {
  return http.request<Result>("post", `/new-product-apply/${id}/refresh-status`);
};
