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

export namespace SystemRoleApi {
  export interface SystemRole {
    [key: string]: any;
    id: string;
    name: string;
    // permissions: string[];
    // remark?: string;
    enabled: 'false' | 'true';
  }
  export interface GetSystemRoleList {
    list: SystemRole[];
  }
  export interface roleDetail {
    menu_ids: number[];
    role: SystemRole;
  }
}

/**
 * 获取角色列表数据
 */
async function getRoleList(id: string) {
  return requestClient.get<SystemRoleApi.GetSystemRoleList>(
    '/identify-service/role/trees',
    { params: { org_id: id } },
  );
}
/**
 *获取角色数据
 */
export async function getRoleDetail(id: string) {
  return requestClient.get<SystemRoleApi.SystemRole>(
    `/identify-service/role/${id}`,
  );
}
/**
 * 创建角色
 * @param data 角色数据
 */
async function createRole(data: Omit<SystemRoleApi.SystemRole, 'id'>) {
  return requestClient.post('/identify-service/role', data);
}

/**
 * 更新角色
 *
 * @param id 角色 ID
 * @param data 角色数据
 */
async function updateRole(
  id: string,
  data: Omit<SystemRoleApi.SystemRole, 'id'>,
) {
  return requestClient.put(`/identify-service/role/${id}`, data);
}

/**
 * 删除角色
 * @param id 角色 ID
 */
async function deleteRole(id: string) {
  return requestClient.delete(`/identify-service/role/`, {
    params: {
      ids: [id],
    },
  });
}
/**
 * 更新角色启用状态
 */
export async function updateRoleStatus(id: string, enabled: boolean) {
  return requestClient.put(`/identify-service/role/${id}/status`, {
    enabled,
  });
}
export { createRole, deleteRole, getRoleList, updateRole };
