import request from '@/utils/request';
import { ReportQuery, ReportForm, ReportVO } from './types';
import { AxiosPromise } from 'axios';

// 查询报表列表
export function listReport(query: ReportQuery): AxiosPromise<ReportVO[]> {
  return request({
    url: '/system/report/list',
    method: 'get',
    params: query
  });
}

// 查询报表详细
export function getReport(reportId: string | number): AxiosPromise<ReportVO> {
  return request({
    url: '/system/report/' + reportId,
    method: 'get'
  });
}

// 新增报表
export function addReport(data: ReportForm) {
  return request({
    url: '/system/report/add',
    method: 'post',
    data: data
  });
}

// 修改报表
export function updateReport(data: ReportForm) {
  return request({
    url: '/system/report/edit',
    method: 'post',
    data: data
  });
}

// 删除报表
export function delReport(reportId: string | number | (string | number)[]) {
  return request({
    url: '/system/report/remove/' + reportId,
    method: 'post'
  });
}

// 测试报表SQL
export function testReport(data: { reportId: string | number, sql: string }) {
  return request({
    url: '/system/report/test',
    method: 'post',
    data: data
  });
}

// 获取报表数据
export function getReportData(params: any) {
  return request({
    url: '/system/report/data',
    method: 'get',
    params: params
  });
}

// 获取报表数据预览
export function getReportDataPreview(data: any) {
  return request({
    url: '/system/report/data/preview',
    method: 'post',
    data: data
  });
}

// 导出报表数据
export function exportReportData(reportId: string | number, params: any) {
  return request({
    url: '/system/report/export/data/' + reportId,
    method: 'get',
    params: params,
    responseType: 'blob'
  });
}
