import { invitationProjectAssignment } from "../../db/runtime/runtime-schema.js";
import { eq } from "drizzle-orm";

//#region src/data-access/runtime/invitationProjectAssignments.ts
const createInvitationProjectAssignments = (db) => async (invitationId, assignments) => {
	if (assignments.length === 0) return;
	await db.insert(invitationProjectAssignment).values(assignments.map((a) => ({
		id: crypto.randomUUID(),
		invitationId,
		projectId: a.projectId,
		projectRole: a.projectRole
	})));
};
const getProjectAssignmentsForInvitation = (db) => async (invitationId) => {
	return await db.select({
		projectId: invitationProjectAssignment.projectId,
		projectRole: invitationProjectAssignment.projectRole
	}).from(invitationProjectAssignment).where(eq(invitationProjectAssignment.invitationId, invitationId));
};
const deleteInvitationProjectAssignments = (db) => async (invitationId) => {
	await db.delete(invitationProjectAssignment).where(eq(invitationProjectAssignment.invitationId, invitationId));
};

//#endregion
export { createInvitationProjectAssignments, deleteInvitationProjectAssignments, getProjectAssignmentsForInvitation };