import request from "@/utils/request";

// 查询租户列表
export function listTenant(query) {
  return request({
    url: "/tenant/list",
    method: "get",
    params: query,
  });
}

// 查询租户详细
export function getTenant(tenantId) {
  return request({
    url: "/tenant/" + tenantId,
    method: "get",
  });
}

// 新增租户
export function addTenant(data) {
  return request({
    url: "/tenant",
    method: "post",
    data: data,
  });
}

// 修改租户
export function updateTenant(data) {
  return request({
    url: "/tenant",
    method: "put",
    data: data,
  });
}

// 删除租户
export function delTenant(tenantId) {
  return request({
    url: "/tenant/" + tenantId,
    method: "delete",
  });
}

// 查看设置
export function getSetting(tenantId) {
  return request({
    url: `/tenant/getSetting/${tenantId}`,
    method: "get",
  });
}

// 刷新参数缓存
export function refreshCache() {
  return request({
    url: "/tenant/refreshCache",
    method: "delete",
  });
}

// 租户模式设置
export function tenantSetting(params) {
  return request({
    url: "/tenant/setting",
    method: "put",
    params,
  });
}

/**
 * 获取数据源列表
 * @return {*}
 */
export function datasourceList(tenantId) {
  return request({
    url: "/tenant/datasource/list",
    method: "GET",
    params: { tenantId },
  });
}

/**
 * 添加数据源
 * @param data
 * @return {*}
 */
export function insertDatasource(data) {
  return request({
    url: "/tenant/datasource",
    method: "POST",
    data,
  });
}

/**
 * 修改数据源
 * @param data
 * @return {*}
 */
export function updateDatasource(data) {
  return request({
    url: "/tenant/datasource",
    method: "PUT",
    data,
  });
}

/**
 * 删除数据源
 * @param ids
 * @return {*}
 */
export function deleteDatasource(ids) {
  return request({
    url: `/tenant/datasource/${ids}`,
    method: "DELETE",
  });
}
