import { request } from "@umijs/max";

export interface DeptVO {
  id: number;
  name: string;
  parentId: number;
  status: number;
  sort: number;
  leaderUserId: number;
  phone: string;
  email: string;
  createTime: Date;
}

export interface DeptReqVO extends PageParam {
  name?: string;
  status?: number;
}

// 查询部门（精简)列表
// export const getSimpleDeptList = async (): Promise<Dept[]> => {
//     return await request.get({ url: "/system/dept/simple-list" });
//   };

export const getSimpleDeptList = async () => {
  return request("/system/dept/simple-list", {
    method: "GET",
  });
};

// 查询部门列表
// export const getDeptPage = async (params: DeptReq): Promise<Dept[]> => {
//     return await request.get({ url: "/system/dept/list", params });
//   };

export const getDeptPage = (params: DeptReqVO) => {
  return request("/system/dept/list", {
    method: "GET",
    params,
  });
};

// 查询部门详情
// export const getDept = async (id: number) => {
//     return await request.get({ url: "/system/dept/get?id=" + id });
//   };

export const getDept = (id: number) => {
  return request("/system/dept/get", {
    method: "GET",
    params: { id },
  });
};

// 新增部门
// export const createDept = async (data: Dept) => {
//     return await request.post({ url: "/system/dept/create", data: data });
//   };

export const createDept = (data: DeptVO) => {
  return request("/system/dept/create", {
    method: "POST",
    data,
  });
};

// 修改部门
// export const updateDept = async (params: Dept) => {
//     return await request.put({ url: "/system/dept/update", data: params });
//   };

export const updateDept = (params: DeptVO) => {
  return request("/system/dept/update", {
    method: "PUT",
    data: params,
  });
};

// 删除部门
// export const deleteDept = async (id: number) => {
//   return await request.delete({ url: "/system/dept/delete?id=" + id });
// };

export const deleteDept = (id: number) => {
  return request("/system/dept/delete", {
    method: "DELETE",
    params: { id },
  });
};
