import httpLogin from "@/api/indexApi";

/**
 * @name 商家信息
 */

// 营业执照上传
export const getUpload = (params: any) => {
  return httpLogin.post(`alienStore/payment/wechatPartner/v3/merchant/media/upload`, params);
};

export const getOcrRequestByBase64 = (params: any) => {
  return httpLogin.post(`alienStore/ali/ocrRequestByBase64`, params);
};

/** POST，storeId 走 URL 查询参数，请求体为 JSON */
export const applyment = (data: Record<string, unknown> | object, storeId: string | number) => {
  return httpLogin.post(`alienStore/payment/wechatPartner/v3/applyment4sub/applyment`, data, {
    params: { storeId },
    headers: { "Content-Type": "application/json;charset=UTF-8" }
  });
};

/** GET，storeId 为路径参数 */
export const applymentExamine = (storeId: string | number) => {
  const id = encodeURIComponent(String(storeId).trim());
  return httpLogin.get(`alienStore/payment/wechatPartner/applyment/store/${id}`);
};

export const getPaymentApplyment = (applymentId: string | number) => {
  const id = encodeURIComponent(String(applymentId).trim());
  return httpLogin.get(`alienStore/payment/wechatPartner/v3/applyment4sub/applyment/applyment_id/${id}`);
};

/** 支付宝直付通图片上传：multipart，字段 image_type + image_content（二进制） */
export interface UploadAlipayImageParams {
  /** 图片格式扩展名，3～16 字符，如 jpg、png（支持 bmp、jpg、jpeg、png、gif） */
  imageType: string;
  /** 图片原始二进制流 */
  imageContent: Blob | File;
  storeId?: string | number | null;
}

export const uploadAlipayImage = (params: UploadAlipayImageParams, axiosConfig?: object) => {
  const fd = new FormData();
  const { imageType, imageContent, storeId } = params;
  if (storeId !== undefined && storeId !== null && String(storeId).trim() !== "") {
    fd.append("storeId", String(storeId));
  }
  fd.append("imageType", imageType);
  fd.append("imageContent", imageContent);
  return httpLogin.post(`alienStore/store/alipay/zft/image/upload`, fd, {
    encrypt: false,
    ...axiosConfig
  });
};

export const getAlipayZftCreate = (params: any) => {
  return httpLogin.post(`alienStore/store/alipay/zft/create`, params);
};

export const getAlipayExamine = (params: any) => {
  return httpLogin.post(`alienStore/store/alipay/zft/order/query`, params);
};
