import httpRequest from '@/utils/axios'

// 获取用户信息
export function getUser() {
  return httpRequest.get('/api/lab/v1/common/permission/role')
}

// 退出登录
export function logout() {
  return httpRequest.get('/api/passport/rest/logout')
}

// 获取oss token
export function getToken() {
  return httpRequest.get('/api/usercenter/aliyun/assume-role')
}

// 获取oss signature
export function getSignature() {
  return httpRequest.get('/api/usercenter/aliyun/get-signature')
}

// 图片上传
export async function uploadFile(data: Record<string, any>) {
  await httpRequest.post(data.host || 'https://webapp-pub.ezijing.com', data, {
    withCredentials: false,
    headers: { 'Content-Type': 'multipart/form-data' },
  })
  return data
}

// 获取公共字典列表
export function getMapList() {
  return httpRequest.get('/api/resource/v1/util/get-data-dictionary-list')
}

// 我的数据集列表
export function getMyList(params?: Partial<{ page: number; 'per-page': number }>) {
  return httpRequest.get('/api/resource/bi/v1/data/my/list', { params })
}

// 查看字段详情
export function getMyField() {
  return httpRequest.get('/api/resource/bi/v1/data/my/field-detail')
}

// 进度查询
export function getProcessProgress(params: { function_name: string }) {
  return httpRequest.get('/api/resource/bi/v1/processing/processing/progress', { params })
}

// 我的数据集列表
export function getChartList(params?: Partial<{ page: number; 'per-page': number }>) {
  return Promise.resolve({
    code: 0,
    message: 'OK',
    data: {
      total: 10,
      list: [
        {
          pk_id: '1',
          type: '柱状图',
          name: '销量统计',
          create_user: 'admin',
          create_time: '2023-07-18 15:00:00',
          update_time: '2023-07-18 15:00:00',
        },
        {
          pk_id: '2',
          type: '折线图',
          name: '销售额趋势',
          create_user: 'admin',
          create_time: '2023-07-18 15:00:00',
          update_time: '2023-07-18 15:00:00',
        },
        {
          pk_id: '3',
          type: '饼图',
          name: '品类分布',
          create_user: 'admin',
          create_time: '2023-07-18 15:00:00',
          update_time: '2023-07-18 15:00:00',
        },
      ],
    },
  })
  return httpRequest.get('/api/resource/bi/v1/data/my/list', { params })
}
