import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { ProjectRoles, commonGetErrorResponses, listUserProjectMembershipsInSpiceDb } from "@inkeep/agents-core";

//#region src/domains/manage/routes/userProjectMemberships.ts
const app = new OpenAPIHono();
const projectRoleEnum = z.enum([
	ProjectRoles.ADMIN,
	ProjectRoles.MEMBER,
	ProjectRoles.VIEWER
]);
const UserProjectMembershipParamsSchema = z.object({
	tenantId: z.string(),
	userId: z.string()
});
app.openapi(createRoute({
	method: "get",
	path: "/",
	summary: "List User Project Memberships",
	description: "List all projects a user has explicit access to and their role in each. Requires authz to be enabled.",
	operationId: "list-user-project-memberships",
	tags: ["User Project Memberships"],
	request: { params: UserProjectMembershipParamsSchema },
	responses: {
		200: {
			description: "List of project memberships for the user",
			content: { "application/json": { schema: z.object({ data: z.array(z.object({
				projectId: z.string(),
				role: projectRoleEnum
			})) }) } }
		},
		...commonGetErrorResponses
	}
}), async (c) => {
	const { tenantId, userId } = c.req.valid("param");
	const memberships = await listUserProjectMembershipsInSpiceDb({
		tenantId,
		userId
	});
	return c.json({ data: memberships });
});
var userProjectMemberships_default = app;

//#endregion
export { userProjectMemberships_default as default };