import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DatabaseLinkVO, DatabaseLinkForm, DatabaseLinkQuery } from '@/api/system/databaseLink/types';

/**
 * 查询数据库连接信息列表
 * @param query
 * @returns {*}
 */

export const listDatabaseLink = (query?: DatabaseLinkQuery): AxiosPromise<DatabaseLinkVO[]> => {
  return request({
    url: '/system/databaseLink/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询数据库连接信息详细
 * @param linkId
 */
export const getDatabaseLink = (linkId: string | number): AxiosPromise<DatabaseLinkVO> => {
  return request({
    url: '/system/databaseLink/' + linkId,
    method: 'get'
  });
};

/**
 * 新增数据库连接信息
 * @param data
 */
export const addDatabaseLink = (data: DatabaseLinkForm) => {
  return request({
    url: '/system/databaseLink',
    method: 'post',
    data: data
  });
};

/**
 * 修改数据库连接信息
 * @param data
 */
export const updateDatabaseLink = (data: DatabaseLinkForm) => {
  return request({
    url: '/system/databaseLink',
    method: 'put',
    data: data
  });
};

/**
 * 删除数据库连接信息
 * @param linkId
 */
export const delDatabaseLink = (linkId: string | number | Array<string | number>) => {
  return request({
    url: '/system/databaseLink/' + linkId,
    method: 'delete'
  });
};


/**
 * 下拉框查询数据库连接信息列表
 * @param query
 * @returns {*}
 */
export function getSysDatabaseLinkList (query) {
    return request({
        url: '/system/databaseLink/getSysDatabaseLinkList',
        method: 'get',
        params: query
    });
};
