import { http } from '@/utils/http/axios';
import { DeptTree, addDeptProps, editDeptProps } from '@/types/dept/type';

/**
 * @description: 部门列表
 */
export function deptList(params) {
  return http.request({
    url: '/dept/list',
    method: 'get',
    params,
  });
}

/**
 * @description: 部门树形列表
 */
export function deptTreeList(params?) {
  return http.request({
    url: '/dept/queryRegionTree',
    method: 'get',
    params,
  });
}

/**
 * @description: 添加部门
 */
export function addDept(params) {
  return http.request({
    url: '/dept/add',
    method: 'post',
    params,
  });
}

/**
 * @description: 编辑部门
 */
export function editDept(params) {
  return http.request({
    url: '/dept/update',
    method: 'post',
    params,
  });
}

/**
 * @description: 部门详情
 */
export function deptInfo(params) {
  return http.request({
    url: '/dept/view',
    method: 'get',
    params,
  });
}

/**
 * @description: 删除部门
 */
export function deleteDept(params) {
  return http.request({
    url: '/dept/delete',
    method: 'post',
    params,
  });
}

/**
 * @description: V4: 添加组织
 */
export function saveDept(params: addDeptProps) {
  return http.request({
    url: '/admin/dept/saveDept',
    method: 'post',
    params,
  });
}

/**
 * @description: V4:编辑组织
 */
export function updateDepartments(params: editDeptProps) {
  return http.request({
    url: '/admin/dept/updateDept',
    method: 'post',
    params,
  });
}

// v4: 获取所有组织
export function getAllDepartments(): Promise<DeptTree[]> {
  return http.request({
    url: '/admin/dept/queryAllDeptTree',
    method: 'post',
  });
}

/**
 * @description:V4： 删除部门
 */
export function deleteDepartments(deptId: number) {
  return http.request(
    {
      url: `/admin/dept/deleteDept?deptId=${deptId}`,
      method: 'DELETE',
    },
    {
      isTransformResponse: false,
    },
  );
}
