Yimaru-BackEnd/internal/domain/notification.go
2025-04-01 19:01:42 +03:00

88 lines
3.3 KiB
Go

package domain
import (
"encoding/json"
"time"
)
type NotificationType string
type NotificationRecieverSide string
type NotificationDeliveryScheme string
type NotificationLevel string
type NotificationErrorSeverity string
type NotificationDeliveryStatus string
type DeliveryChannel string
const (
NotificationTypeCashOutSuccess NotificationType = "cash_out_success"
NotificationTypeDepositSuccess NotificationType = "deposit_success"
NotificationTypeBetPlaced NotificationType = "bet_placed"
NotificationTypeDailyReport NotificationType = "daily_report"
NotificationTypeHighLossOnBet NotificationType = "high_loss_on_bet"
NotificationTypeBetOverload NotificationType = "bet_overload"
NotificationTypeSignUpWelcome NotificationType = "signup_welcome"
NotificationTypeOTPSent NotificationType = "otp_sent"
NotificationRecieverSideAdmin NotificationRecieverSide = "admin"
NotificationRecieverSideCustomer NotificationRecieverSide = "customer"
NotificationDeliverySchemeBulk NotificationDeliveryScheme = "bulk"
NotificationDeliverySchemeSingle NotificationDeliveryScheme = "single"
NotificationLevelInfo NotificationLevel = "info"
NotificationLevelError NotificationLevel = "error"
NotificationLevelWarning NotificationLevel = "warning"
NotificationLevelSuccess NotificationLevel = "success"
NotificationErrorSeverityLow NotificationErrorSeverity = "low"
NotificationErrorSeverityMedium NotificationErrorSeverity = "medium"
NotificationErrorSeverityHigh NotificationErrorSeverity = "high"
NotificationErrorSeverityCritical NotificationErrorSeverity = "critical"
NotificationErrorSeverityFatal NotificationErrorSeverity = "fatal"
DeliveryStatusPending NotificationDeliveryStatus = "pending"
DeliveryStatusSent NotificationDeliveryStatus = "sent"
DeliveryStatusFailed NotificationDeliveryStatus = "failed"
DeliveryChannelEmail DeliveryChannel = "email"
DeliveryChannelSMS DeliveryChannel = "sms"
DeliveryChannelPush DeliveryChannel = "push"
DeliveryChannelInApp DeliveryChannel = "in-app"
)
type NotificationPayload struct {
Headline string
Message string
Tags []string
}
type Notification struct {
ID string `json:"id"`
RecipientID string `json:"recipient_id"`
Type NotificationType `json:"type"`
Level NotificationLevel `json:"level"`
ErrorSeverity *NotificationErrorSeverity `json:"error_severity"`
Reciever NotificationRecieverSide `json:"reciever"`
IsRead bool `json:"is_read"`
DeliveryStatus NotificationDeliveryStatus `json:"delivery_status,omitempty"`
DeliveryChannel DeliveryChannel `json:"delivery_channel,omitempty"`
Payload NotificationPayload `json:"payload"`
Priority int `json:"priority,omitempty"`
Version int `json:"-"`
Timestamp time.Time `json:"timestamp"`
Metadata json.RawMessage `json:"metadata,omitempty"`
}
func (n *Notification) ToJSON() ([]byte, error) {
return json.Marshal(n)
}
func FromJSON(data []byte) (*Notification, error) {
var n Notification
err := json.Unmarshal(data, &n)
if err != nil {
return nil, err
}
return &n, nil
}