import { db } from '../db/index.js';
import { auditLog } from '../db/schema.js';

export async function logAudit({ userId, action, entityType, entityId, metadata }) {
  try {
    await db.insert(auditLog).values({
      userId: userId || null,
      action,
      entityType: entityType || null,
      entityId: entityId || null,
      metadata: metadata || null,
    });
  } catch (err) {
    console.error('Audit log error:', err.message);
  }
}
