import request from '@/utils/request'

const baseUrl = import.meta.env.VITE_APP_BASE_API
// 有条件List查询
export function index() {
  return request({
    url: baseUrl + '/datasource/Index',
    method: 'post'
  })
}

// 代码生成
export function build(data) {
  return request({
    url: baseUrl + '/datasource/build',
    method: 'post',
    data
  })
}

export function download(url) {
  return request({
    url: baseUrl + '/datasource/' + url,
    method: 'get',
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/json; application/octet-stream'
    }
  })
}

// 获取数据源配置信息
export function loadDataSource(data) {
  return request({
    url: baseUrl + '/datasource/loadDataSource',
    method: 'post',
    data
  })
}

// 连接数据源
export function getDataSource() {
  return request({
    url: baseUrl + '/datasource/getDataSource',
    method: 'post'
  })
}

// 通过Id查询
export function getList(dataBase, tableName) {
  return request({
    url: `/datasource/getList/${dataBase}/${tableName}`,
    method: 'get'
  })
}

// 通过Id查询
export function getTableList(dataBase) {
  return request({
    url: `/datasource/getTableList/${dataBase}`,
    method: 'get'
  })
}

// 通用查询
export function query(data) {
  return request({
    url: baseUrl + '/datasource/query',
    method: 'post',
    data
  })
}
