import request from '@/utils/request'

// 通过图表对象获取数据
export const getData = async (data:any) => {
  delete data.data
  return request.post('/chartData/getData', data).then((res:any) => {
    if (res.code === 0) {
      return res?.data
    } else {
      return res
    }
  })
}

export const innerExportDetails = async (data: any) => {
  return request.post('/chartData/innerExportDetails', data, {
    method: 'post',
    responseType: 'blob'
  })
}

export const innerExportDataSetDetails = async (data: any) => {
  return request.post('/chartData/innerExportDataSetDetails', data, {
    method: 'post',
    responseType: 'blob'
  })
}

// 通过图表id获取数据
export const getChart = async (id: string) => {
  return request.post(`/chart/getChart/${id}`, {}).then(res => {
    return res?.data
  })
}

// 单个图表保存测试
export const saveChart = async (data: any) => {
  delete data.data
  return request.post('/chart/save', data).then(res => {
    return res?.data
  })
}

// 获取单个字段枚举值
export const getFieldData = async ({ fieldId, fieldType, data }: { fieldId: string, fieldType: string, data: any }) => {
  delete data.data
  return request
    .post(`/chartData/getFieldData/${fieldId}/${fieldType}`, data)
    .then(res => {
      return res
    })
}

// 获取下钻字段枚举值
export const getDrillFieldData = async ({ fieldId, data }: { fieldId: string, data: any }) => {
  delete data.data
  return request.post(`/chartData/getDrillFieldData/${fieldId}`, data).then(res => {
    return res
  })
}

export const getChartDetail = async (id: string) => {
  return request.post(`chart/getDetail/${id}`, {}).then(res => {
    return res
  })
}

export const checkSameDataSet = async (viewIdSource: string, viewIdTarget: string) =>
  request.get('/chart/checkSameDataSet/' + viewIdSource + '/' + viewIdTarget)
