// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type {NextApiRequest, NextApiResponse} from "next";
import {app} from "@/firebase";
import {getFirestore, collection, getDocs, query, where, setDoc, doc, getDoc, deleteDoc} from "firebase/firestore";
import {withIronSessionApiRoute} from "iron-session/next";
import {sessionOptions} from "@/lib/session";
import {uuidv4} from "@firebase/util";

const db = getFirestore(app);

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
	if (req.method === "GET") return GET(req, res);

	res.status(404).json({ok: false});
}

async function GET(req: NextApiRequest, res: NextApiResponse) {
	const {id} = req.query;

	const snapshot = await getDoc(doc(db, "stats", id as string));
	if (!snapshot.exists()) return res.status(404).json({id: snapshot.id});

	res.status(200).json({...snapshot.data(), id: snapshot.id});
}
