package report import ( "context" "encoding/json" "errors" "fmt" "strings" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain" ) var ( ErrInvalidRequestedByID = errors.New("requested_by needs to be filled in to send report notification") ) func (s *Service) SendReportRequestNotification(ctx context.Context, param domain.ReportRequestDetail) error { if !param.RequestedBy.Valid { return ErrInvalidRequestedByID } var ( headline string message string level domain.NotificationLevel ) switch param.Status { case domain.SuccessReportRequest: headline = "Report Ready for Download" message = fmt.Sprintf( "Your %s report has been successfully generated and is now available for download.", strings.ToLower(string(param.Type)), ) level = domain.NotificationLevelSuccess case domain.RejectReportRequest: headline = "Report Generation Failed" message = fmt.Sprintf( "We were unable to generate your %s report. Please review your request and try again.", strings.ToLower(string(param.Type)), ) level = domain.NotificationLevelError default: return fmt.Errorf("unsupported request status: %v", param.Status) } raw, _ := json.Marshal(map[string]any{ "report_id": param.ID, "type": param.Type, "status": param.Status, }) n := &domain.Notification{ RecipientID: param.RequestedBy.Value, DeliveryStatus: domain.DeliveryStatusPending, IsRead: false, Type: domain.NotificationTypeReportRequest, Level: level, Reciever: domain.NotificationRecieverSideCustomer, DeliveryChannel: domain.DeliveryChannelInApp, Payload: domain.NotificationPayload{ Headline: headline, Message: message, }, Priority: 2, Metadata: raw, } return s.notificationSvc.SendNotification(ctx, n) }