import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import { completeOnboardingSchema } from "../../shared/schemas.ts";
import { completeOnboarding } from "../services/onboarding.service.ts";

type Env = { Variables: { db?: any; userId?: number } };

const app = new Hono<Env>();

// POST /api/onboarding/complete
app.post(
	"/complete",
	zValidator("json", completeOnboardingSchema),
	async (c) => {
		const database = c.get("db");
		const userId = c.get("userId")!;
		const { globalItemIds } = c.req.valid("json");

		const result = await completeOnboarding(database, userId, globalItemIds);
		return c.json(result);
	},
);

export { app as onboardingRoutes };
