import { http } from '@/utils/http/axios';
import type { tenantFormType } from '@/types/tenant/type';

/**
 * @description: 租户列表
 */
export function tenantList(params) {
  return http.request({
    url: '/tenant/list',
    method: 'get',
    params,
  });
}

/**
 * @description: 添加租户
 */
export function addTenant(data) {
  return http.request({
    url: '/tenant/add',
    method: 'post',
    data,
  });
}

/**
 * @description: 删除租户
 */
export function deleteTenant(data) {
  return http.request({
    url: '/tenant/delete',
    method: 'post',
    data,
  });
}

/**
 * @description: 编辑租户
 */
export function editTenant(data) {
  return http.request({
    url: '/tenant/update',
    method: 'post',
    data,
  });
}

/**
 * @description: 租户详情
 */
export function tenantInfo(params) {
  return http.request({
    url: '/tenant/view',
    method: 'get',
    params,
  });
}

/** 获取有总部权限时的所有租户 */
export function getListUseZongbu() {
  return http.request(
    {
      url: '/tenant/listUseZongbu',
      method: 'get',
    },
    { isShowErrorMessage: false, isShowMessage: false },
  );
}

/**
 * @description: 查询租户树
 */
export function queryTenantTreeApi(params: { tenantName: string; tenantCode: string }) {
  return http.request({
    url: '/admin/tenant/queryTenantTree',
    method: 'post',
    params,
  });
}

/**
 * @description: 添加租户（新）
 */

export function saveTenantApi(params: tenantFormType) {
  return http.request({
    url: '/admin/tenant/saveTenant',
    method: 'post',
    params,
  });
}

/**
 * @description: 删除租户（新）
 */

export function deleteTenantApi(tenantId: number) {
  return http.request({
    url: `/admin/tenant/deleteTenant?tenantId=${tenantId}`,
    method: 'post',
  });
}

/**
 * @description: 修改租户（新）
 */

export function updateTenantApi(params: tenantFormType) {
  return http.request({
    url: '/admin/tenant/updateTenant',
    method: 'post',
    params,
  });
}

/* V4: 获取租户列表 */
export function queryListTenant() {
  return http.request(
    {
      url: '/admin/tenant/listTenantForTargetTenant',
      method: 'post',
    },
    { isShowErrorMessage: false, isShowMessage: false, ignoreTargetTenantId: true },
  );
}
