import http from '@/api'
import { ConnectionVO, ConnectionForm, ConnectionQuery } from '@/api/interface/db/connection'
/**
 * @name 查询数据库链接列表
 * @param query 参数
 * @returns 返回列表
 */
export const listConnectionApi = (query: ConnectionQuery) => {
  return http.get<ConnectionVO[]>('/db/connection/list', query, { loading: true })
}

/**
 * @name 查询数据库链接详细
 * @param id id
 * @returns returns
 */
export const getConnectionApi = (id: string | number) => {
  return http.get<ConnectionVO>(`/db/connection/${id}`)
}

/**
 * @name 测试数据库连接
 * @param id id
 * @returns returns
 */
export const testApi = (id: string | number) => {
  return http.get<any>(`/db/connection/test/${id}`)
}
/**
 * @name 获取连接名称
 * @returns returns
 */
export const getNameListApi = () => {
  return http.get<any>(`/db/connection/list/name`)
}

/**
 * @name 查询数据库产品类型
 * @returns returns
 */
export const getTypesApi = () => {
  return http.get<any>(`/db/connection/types`)
}

/**
 * @name 查询数据库链驱动
 * @param type type
 * @returns returns
 */
export const getDriversApi = (type: string | number) => {
  return http.get<any>(`/db/connection/drivers/${type}`)
}

/**
 * @name 新增数据库链接
 * @param data data
 * @returns returns
 */
export const addConnectionApi = (data: ConnectionForm) => {
  return http.post<any>('/db/connection', data, { loading: false })
}

/**
 * @name 修改数据库链接
 * @param data data
 * @returns returns
 */
export const updateConnectionApi = (data: ConnectionForm) => {
  return http.put<any>('/db/connection', data, { loading: false })
}

/**
 * @name 删除数据库链接
 * @param id id
 * @returns returns
 */
export const delConnectionApi = (id: string | number | Array<string | number>) => {
  return http.delete<any>(`/db/connection/${id}`)
}
