import { prisma } from "@/lib/prisma";
import { auth } from "@/auth";

export async function logAction(
  action: string,
  entity: string,
  entityId?: string | null,
  details?: string | null,
  linkUrl?: string | null
) {
  try {
    const session = await auth();
    const staffId = session?.user?.id;
    if (!staffId) return;

    await prisma.auditLog.create({
      data: {
        staffId,
        action,
        entity,
        entityId,
        details,
        linkUrl,
        syncStatus: 1
      }
    });
  } catch (error) {
    console.error("Failed to write audit log:", error);
  }
}
