package dev.lions.unionflow.server.security;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * Événement CDI émis après chaque écriture audit trail (Sprint 16.C).
 *
 * <p>Permet aux observers ({@code AuditNotificationService}) de réagir sans coupler le
 * service d'écriture aux services de notification. Pattern Observer via {@code @Observes}.
 *
 * @since 2026-04-25 (Sprint 16.C — transparency)
 */
public record AuditOperationLoggedEvent(
    UUID operationId,
    UUID userId,
    String userEmail,
    UUID organisationActiveId,
    String actionType,
    String entityType,
    UUID entityId,
    String description,
    Boolean sodCheckPassed,
    LocalDateTime operationAt
) {
  /** Renvoie true si cette opération mérite une notification (sensible). */
  public boolean estSensible() {
    if (Boolean.FALSE.equals(sodCheckPassed)) return true;
    if (actionType == null) return false;
    return switch (actionType) {
      case "DELETE", "PAYMENT_INITIATED", "PAYMENT_CONFIRMED", "PAYMENT_FAILED",
           "BUDGET_APPROVED", "AID_REQUEST_APPROVED", "EXPORT", "VALIDATE" -> true;
      default -> false;
    };
  }
}
