import { Session } from "@/hooks/useSessions";
import client from "@/lib/mongodb";

const db = client.db(process.env.MONGODB_DB);

export const getSessionsByUser = async (id: string, limit = 0, filter = {}) =>
	await db
		.collection("sessions")
		.find<Session>({ user: id, ...filter })
		.limit(limit || 0)
		.toArray();

export const getSessionByAssignment = async (assignmentID: string) =>
	await db
		.collection("sessions")
		.findOne<Session>({ "assignment.id": assignmentID })

export const getSessionsByAssignments = async (assignmentIDs: string[]) =>
	await db
		.collection("sessions")
		.find<Session>({ "assignment.id": { $in: assignmentIDs } }).toArray()
