import { createFileRoute } from "@tanstack/react-router";
import { getLogById } from "../../proxy/store";

export const Route = createFileRoute("/api/logs/$id")({
  server: {
    handlers: {
      GET: async ({ params }: { params: { id: string } }) => {
        const id = Number(params.id);
        if (isNaN(id)) {
          return Response.json({ error: "Invalid ID" }, { status: 400 });
        }

        const log = await getLogById(id);
        if (log === null) {
          return Response.json({ error: "Log not found" }, { status: 404 });
        }

        return Response.json(log);
      },
    },
  },
});
