import {Session} from "@/hooks/useSessions";
import { Entity } from "@/interfaces/entity";
import {Invite, InviteWithEntity} from "@/interfaces/invite";
import {User} from "@/interfaces/user";
import client from "@/lib/mongodb";

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

export const getInvitesByInvitee = async (id: string, limit?: number) =>
	await db
		.collection("invites")
		.find<Invite>({to: id})
		.limit(limit || 0)
		.toArray();

export const convertInvitersToEntity = async (invite: Invite): Promise<InviteWithEntity> => ({
	...invite,
	entity: (await db.collection("entities").findOne<Entity>({id: invite.entity })) ?? undefined,
});
