//#region src/gateway/hono/routes/extension-gateway.ts
function registerExtensionGatewayRoutes(authenticated, deps) {
	const { service } = deps;
	const extensionRegistry = service.getExtensionRegistry?.();
	if (extensionRegistry) {
		const httpRoutes = extensionRegistry.httpRoutes;
		for (const [path, handler] of httpRoutes) {
			authenticated.post(path, async (c) => {
				const response = await handler({
					method: c.req.method,
					url: c.req.url,
					headers: c.req.header(),
					body: await c.req.json().catch(() => ({}))
				});
				if (response) {
					if (response.status) c.status(response.status);
					if (response.headers) for (const [key, value] of Object.entries(response.headers)) c.header(key, String(value));
					if (response.body !== void 0) return c.json(response.body);
				}
				return c.text("");
			});
			authenticated.get(path, async (c) => {
				const response = await handler({
					method: c.req.method,
					url: c.req.url,
					headers: c.req.header()
				});
				if (response) {
					if (response.status) c.status(response.status);
					if (response.headers) for (const [key, value] of Object.entries(response.headers)) c.header(key, String(value));
					if (response.body !== void 0) return c.json(response.body);
				}
				return c.text("");
			});
		}
	}
	authenticated.post("/api/gateway/:method", async (c) => {
		const method = c.req.param("method");
		const params = await c.req.json().catch(() => ({}));
		try {
			const result = await service.invokeGatewayMethod(method, params);
			return c.json({
				ok: true,
				result
			});
		} catch (err) {
			return c.json({
				ok: false,
				error: err instanceof Error ? err.message : "Unknown error"
			}, 400);
		}
	});
}
//#endregion
export { registerExtensionGatewayRoutes };

//# sourceMappingURL=extension-gateway.js.map