import apiRequest from '@/network/http/apiRequest'

/**
 * 获取当前数据库所有表格
 * @returns
 */
export function getTableByList() {
  return apiRequest({
    url: '/daas/db/tables',
    method: 'GET',
  })
}

/**
 * 获取目标数据库表的字段定义
 * @returns
 */
export function getTableFieldsByList(tableName: string) {
  return apiRequest({
    url: `/daas/db/table/fields/${tableName}`,
    method: 'GET',
  })
}

/**
 * 获取DB列表
 * @param data
 * @returns
 */
export function getDBByList(data: any) {
  return apiRequest({
    url: '/daas/db',
    method: 'GET',
    params: data,
  })
}

/**
 * 根据Id获取DB
 * @param dbId
 * @returns
 */
export function getDBById(dbId: number) {
  return apiRequest({
    url: `/daas/db/${dbId}`,
    method: 'GET',
  })
}

/**
 * 添加DB
 * @param data
 * @returns
 */
export function createDB(data: any) {
  return apiRequest({
    url: '/daas/db/add',
    method: 'POST',
    data,
  })
}

/**
 * 更新DB
 * @param data
 * @returns
 */
export function updateDB(data: any) {
  return apiRequest({
    url: '/daas/db/update',
    method: 'PUT',
    data,
  })
}

/**
 * 删除DB
 * @param dbId
 * @returns
 */
export function deleteDBById(dbId: number) {
  return apiRequest({
    url: `/daas/db/${dbId}`,
    method: 'DELETE',
  })
}
