/**
 * 通用接口
 */
import type { SendCodeParams, SendCodeResult, UploadImageResult } from './types';
import { get, post, upload } from '@/utils/request';

enum URL {
  upload = '/common/upload',
  sendCode = '/sendCode',
  barCode = '/ext2/qr/barimg',
  qrCode = '/ext2/qr/qrimg'
}

// 图片上传
export const uploadImage = (imagePath: string) =>
  upload<UploadImageResult>({ url: URL.upload, filePath: imagePath, name: 'file' });

// 发送验证码
export const sendCode = (data: SendCodeParams) => post<SendCodeResult>({ url: URL.sendCode, data });

export const generateBarCode = (data: string) => get<ArrayBuffer>({
  url: `${URL.barCode}?v=${data}`,
  responseType: 'arraybuffer'
});
export const generateQrCode = (data: string) => get<ArrayBuffer>({
  url: `${URL.qrCode}?v=${data}`,
  responseType: 'arraybuffer'
});
