import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SimilarRecognitionVO, SimilarRecognitionForm, SimilarRecognitionQuery } from '@/api/customer/similarRecognition/types';

/**
 * 查询相似客户认定列表
 * @param query
 * @returns {*}
 */

export const listSimilarRecognition = (query?: SimilarRecognitionQuery): AxiosPromise<SimilarRecognitionVO[]> => {
  return request({
    url: '/customer/similarRecognition/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询相似客户认定详细
 * @param recordId
 */
export const getSimilarRecognition = (recordId: string | number): AxiosPromise<SimilarRecognitionVO> => {
  return request({
    url: '/customer/similarRecognition/' + recordId,
    method: 'get'
  });
};

/**
 * 新增相似客户认定
 * @param data
 */
export const addSimilarRecognition = (data: SimilarRecognitionForm) => {
  return request({
    url: '/customer/similarRecognition',
    method: 'post',
    data: data
  });
};

/**
 * 修改相似客户认定
 * @param data
 */
export const updateSimilarRecognition = (data: SimilarRecognitionForm) => {
  return request({
    url: '/customer/similarRecognition',
    method: 'put',
    data: data
  });
};

/**
 * 删除相似客户认定
 * @param recordId
 */
export const delSimilarRecognition = (recordId: string | number | Array<string | number>) => {
  return request({
    url: '/customer/similarRecognition/' + recordId,
    method: 'delete'
  });
};

/**
 * 异步导出相似客户认定列表
 * @param query 查询条件
 * @returns {Promise} 返回任务ID
 */
export const exportSimilarRecognitionAsync = (query?: SimilarRecognitionQuery): AxiosPromise<string> => {
  return request({
    url: '/customer/similarRecognition/export/async',
    method: 'post',
    data: query
  });
};

/**
 * 查询导出任务进度
 * @param taskId 任务ID
 * @returns {Promise} 返回任务信息
 */
export const getExportProgress = (taskId: string): AxiosPromise<any> => {
  return request({
    url: '/customer/similarRecognition/export/progress/' + taskId,
    method: 'get'
  });
};

/**
 * 取消下载
 */
export const cancelExportTask = (taskId: string): AxiosPromise<void> => {
  return request({
    url: `/customer/similarRecognition/export/cancel/${taskId}`,
    method: 'post'
  });
};

/**
 * 查询当前用户最近的未完成的导出任务
 */
export const getLatestRunningTask = (): AxiosPromise<any> => {
  return request({
    url: '/customer/similarRecognition/export/latest',
    method: 'get'
  });
};