import axiosInstance from '../../utils/axios';

// 分页参数类型
export interface PageParam {
  pageNo?: number;
  pageSize?: number;
  [key: string]: any;
}

// 部门 VO 类型
export interface DeptVO {
  id?: number;
  name: string;
  parentId: number;
  status: number;
  sort: number;
  leaderUserId?: number;
  phone?: string;
  email?: string;
  createTime?: Date | string;
}

// 部门管理 API
export const deptApi = {
  // 查询部门（精简）列表
  getSimpleDeptList: (): Promise<DeptVO[]> => {
    return axiosInstance.get('/system/dept/simple-list');
  },

  // 查询部门列表
  getDeptPage: (params: PageParam): Promise<DeptVO[]> => {
    return axiosInstance.get('/system/dept/list', { params });
  },

  // 查询部门详情
  getDept: (id: number): Promise<DeptVO> => {
    return axiosInstance.get(`/system/dept/get?id=${id}`);
  },

  // 新增部门
  createDept: (data: DeptVO): Promise<void> => {
    return axiosInstance.post('/system/dept/create', data);
  },

  // 修改部门
  updateDept: (data: DeptVO): Promise<void> => {
    return axiosInstance.put('/system/dept/update', data);
  },

  // 删除部门
  deleteDept: (id: number): Promise<void> => {
    return axiosInstance.delete(`/system/dept/delete?id=${id}`);
  },
};

