import { requestClient } from '#/api/request';

export namespace DeptApi {
  export interface Dept {
    remark: string;
    createTime: string;
    name: string;
    enabled: string;
    id: string;
    children?: Dept[];
  }

  export interface DeptRecord extends Dept {
    id: string;
  }

  export interface DeptTreeData {
    id: number;
    label: string;
    children?: DeptTreeData[];
  }
}

// 添加部门
export function createDept(data: DeptApi.Dept) {
  return requestClient.post(`/rest/dept`, data);
}

// 更新部门信息
export function updateDept(id: string, data: DeptApi.DeptRecord) {
  return requestClient.patch(`/rest/dept/${id}`, data);
}

// 删除部门
export function removeDept(id: string) {
  return requestClient.delete(`/rest/dept/${id}`);
}

// 模糊查询获取部门列表
export function queryDeptList(data: DeptApi.DeptRecord) {
  return requestClient.get('/rest/dept', { data });
}

// 获取部门列表
export function deptList() {
  return requestClient.get(`/rest/dept`);
}

// 启用状态
export function enabledDept(id: string) {
  return requestClient.patch(`/rest/dept/toggle/${id}`, id);
}

export function getAllDeptTree(id?: number | string) {
  return requestClient.get('/rest/dept/tree', { params: { id } });
}

// export function getDeptTree(params?: Partial<DeptRecord>) {
//   return axios.get<DeptRecord[]>(`/dept/trees`, {
//     params,
//     paramsSerializer: (obj) => {
//       return qs.stringify(obj);
//     },
//   });
// }
// export function listDepts(params?: ListParams<Partial<DeptRecord>>) {
//   return axios.get<DeptRecord[]>(`/dept`, {
//     params,
//     paramsSerializer: (obj) => {
//       return qs.stringify(obj);
//     },
//   });
// }
// export function queryDepts(params?: ListParams<Partial<DeptRecord>>) {
//   return queryList(`/dept`, params);
// }
