import {Role} from "@/interfaces/entity";
import client from "@/lib/mongodb";

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

export const getRolesByEntities = async (entityIDs: string[]) =>
	await db
		.collection("roles")
		.find<Role>({entityID: {$in: entityIDs}})
		.toArray();

export const getRolesByEntity = async (entityID: string) => await db.collection("roles").find<Role>({entityID}).toArray();

export const getRole = async (id: string) => (await db.collection("roles").findOne<Role>({id})) ?? undefined;
