import runDbClient_default from "../../../data/db/runDbClient.js";
import { sessionAuth } from "../../../middleware/sessionAuth.js";
import { createApiError, getPendingInvitationsByEmail } from "@inkeep/agents-core";
import { Hono } from "hono";

//#region src/domains/manage/routes/invitations.ts
const invitationsRoutes = new Hono();
invitationsRoutes.use("*", sessionAuth());
invitationsRoutes.get("/pending", async (c) => {
	const email = c.req.query("email");
	const authenticatedEmail = c.get("userEmail");
	if (!email) throw createApiError({
		code: "bad_request",
		message: "Email parameter is required"
	});
	if (email !== authenticatedEmail) throw createApiError({
		code: "forbidden",
		message: "Cannot access invitations for another email"
	});
	const response = (await getPendingInvitationsByEmail(runDbClient_default)(email)).map((inv) => ({
		...inv,
		expiresAt: inv.expiresAt instanceof Date ? inv.expiresAt.getTime() : inv.expiresAt
	}));
	return c.json(response);
});
var invitations_default = invitationsRoutes;

//#endregion
export { invitations_default as default };