import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { VersionManagementVO, VersionManagementForm, VersionManagementQuery } from '@/api/system/business/versionManagement/types';

/**
 * 查询App版本管理列表
 * @param query
 * @returns {*}
 */

export const listVersionManagement = (query?: VersionManagementQuery): AxiosPromise<VersionManagementVO[]> => {
  return request({
    url: '/business/versionManagement/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询App版本管理详细
 * @param id
 */
export const getVersionManagement = (id: string | number): AxiosPromise<VersionManagementVO> => {
  return request({
    url: '/business/versionManagement/' + id,
    method: 'get'
  });
};

/**
 * 新增App版本管理
 * @param data
 */
export const addVersionManagement = (data: VersionManagementForm) => {
  return request({
    url: '/business/versionManagement',
    method: 'post',
    data: data
  });
};

/**
 * 修改App版本管理
 * @param data
 */
export const updateVersionManagement = (data: VersionManagementForm) => {
  return request({
    url: '/business/versionManagement',
    method: 'put',
    data: data
  });
};

/**
 * 删除App版本管理
 * @param id
 */
export const delVersionManagement = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/versionManagement/' + id,
    method: 'delete'
  });
};
/**
 * 获取App版本管理
 * @param id
 */
export const getMaxNewAppVersion = () => {
  return request({
    url: '/business/versionManagement/getMaxNewAppVersion',
    method: 'get'
  });
};
/**
 * 苹果下载
 */
export const downloadAppIosUrl = () => {
  return request({
    url: '/business/versionManagement/downloadAppIosUrl',
    method: 'get'
  });
};
export const generateAppDownLoadFile = (id: string | number): AxiosPromise<VersionManagementVO> => {
  return request({
    url: '/business/versionManagement/generateAppDownLoadFile/' + id,
    method: 'get'
  });
};
/**
 * 上传 比赛图标
 * @param file 文件
 */
export const uploadAppFileAsync = async (file: File) => {
  const formData = new FormData();
  formData.append('file', file); // 后端接收的参数名是 "file"
  const res = await request({
    url: '/business/versionManagement/uploadAppFileAsync',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
  return res;
};
