import { prisma } from '../config/database';
import { Prisma } from '@prisma/client';

interface AuditLogParams {
  actorId?: string;
  action: string;
  entityType: string;
  entityId?: string;
  oldValue?: Record<string, unknown>;
  newValue?: Record<string, unknown>;
  ipAddress?: string;
}

export async function createAuditLog(params: AuditLogParams): Promise<void> {
  await prisma.auditLog.create({
    data: {
      actorId: params.actorId,
      action: params.action,
      entityType: params.entityType,
      entityId: params.entityId,
      oldValue: params.oldValue as Prisma.InputJsonValue ?? undefined,
      newValue: params.newValue as Prisma.InputJsonValue ?? undefined,
      ipAddress: params.ipAddress,
    },
  });
}
