import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SmscountVO, SmscountForm, SmscountQuery } from '@/api/msg/smscount/types';
import { SettlementQuery, SettlementVO } from '@/api/msg/settlement/types';

/**
 * 查询短信统计查询列表
 * @param query
 * @returns {*}
 */

export const listSmscount = (query?: SmscountQuery): AxiosPromise<SmscountVO[]> => {
  return request({
    url: '/msg/smscount/list',
    method: 'get',
    params: query
  });
};
export const getSettlement = (query?: SmscountQuery): AxiosPromise<SmscountVO[]> => {
  return request({
    url: '/msg/settlement/list',
    method: 'get',
    params: query
  });
};
export const getChecklist = (query?: SmscountQuery): AxiosPromise<SmscountVO[]> => {
  return request({
    url: '/msg/checklist/list',
    method: 'get',
    params: query
  });
};
export const postSettlement = (query?: SmscountQuery) => {
  return request({
    url: '/msg/settlement/listpost',
    method: 'post',
    data: query
  });
};
/**
 * 查询短信统计查询详细
 * @param sendId
 */
export const getSmscount = (sendId: string | number): AxiosPromise<SmscountVO> => {
  return request({
    url: '/msg/smscount/' + sendId,
    method: 'get'
  });
};

/**
 * 新增短信统计查询
 * @param data
 */
export const addSmscount = (data: SmscountForm) => {
  return request({
    url: '/msg/smscount',
    method: 'post',
    data: data
  });
};

/**
 * 修改短信统计查询
 * @param data
 */
export const updateSmscount = (data: SmscountForm) => {
  return request({
    url: '/msg/smscount',
    method: 'put',
    data: data
  });
};

/**
 * 删除短信统计查询
 * @param sendId
 */
export const delSmscount = (sendId: string | number | Array<string | number>) => {
  return request({
    url: '/msg/smscount/' + sendId,
    method: 'delete'
  });
};

/**
 * 异步导出相似客户认定列表
 * @param query 查询条件
 * @returns {Promise} 返回任务ID
 */
export const exportSmsChecklistAsync = (data: any) => {
  return request({
    url: '/msg/checklist/export/async',
    method: 'post',
    data: data
  });
};

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

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

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