using Fengling.RiskControl.Application.Services; using Fengling.RiskControl.Domain.Aggregates.RiskAlerts; using Fengling.RiskControl.Domain.Events; using MediatR; namespace Fengling.RiskControl.Application.Events; public class RiskAlertTriggeredEventHandler : INotificationHandler { private const int ALERT_TRIGGER_THRESHOLD = 30; private readonly IRiskAlertService _alertService; public RiskAlertTriggeredEventHandler(IRiskAlertService alertService) { _alertService = alertService; } public async Task Handle(RiskAlertTriggeredEvent notification, CancellationToken cancellationToken) { if (notification.RiskScore < ALERT_TRIGGER_THRESHOLD) return; var priority = notification.RiskScore switch { >= 80 => RiskAlertPriority.Critical, >= 60 => RiskAlertPriority.High, >= 40 => RiskAlertPriority.Medium, _ => RiskAlertPriority.Low }; await _alertService.CreateAlertAsync( notification.MemberId, notification.AlertType, notification.Reason, priority); } }