import { prisma } from "./prisma";
import { Prisma } from "../../prisma/generated/client";

export async function logAuditEvent(
  tx: Prisma.TransactionClient,
  params: {
    actorType: "SYSTEM" | "AGENT" | "USER";
    actorId?: string;
    action: string;
    entityType: "TASK" | "CLAIM" | "SUBMISSION" | "JUDGE_RESULT";
    entityId: string;
    beforeState?: any;
    afterState?: any;
    reason?: string;
    metadata?: any;
  }
) {
  return tx.auditEvent.create({
    data: {
      actorType: params.actorType,
      actorId: params.actorId,
      action: params.action,
      entityType: params.entityType,
      entityId: params.entityId,
      beforeState: params.beforeState ?? Prisma.JsonNull,
      afterState: params.afterState ?? Prisma.JsonNull,
      reason: params.reason,
      metadata: params.metadata ?? Prisma.JsonNull,
    },
  });
}
