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

export namespace SystemDeptApi {
  export interface SystemDept {
    [key: string]: any;
    children?: SystemDept[];
    id: string;
    name: string;
    remark?: string;
    status: 0 | 1;
  }
}

/**
 * 获取部门列表数据
 */
async function getDeptList() {
  return requestClient.get<{ list: Array<SystemDeptApi.SystemDept> }>(
    '/identify-service/org/trees',
  );
}

/**
 * 创建部门
 * @param data 部门数据
 */
async function createDept(
  data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
) {
  return requestClient.post('/identify-service/org', data);
}

/**
 * 更新部门
 *
 * @param id 部门 ID
 * @param data 部门数据
 */
async function updateDept(
  id: string,
  data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
) {
  return requestClient.put(`/identify-service/org/${id}`, data);
}

/**
 * 删除部门
 * @param id 部门 ID
 */
async function deleteDept(id: string) {
  return requestClient.delete(`/identify-service/org/${id}`);
}
/**
 * 更新组织状态
 */
export async function updateDeptEnable(id: string, enabled: boolean) {
  return requestClient.put(`/identify-service/org/${id}/status`, {
    enabled,
  });
}
export { createDept, deleteDept, getDeptList, updateDept };
