package notifications import ( "encoding/json" messaging "github.com/tech/sendico/pkg/messaging/envelope" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" "go.mongodb.org/mongo-driver/bson/primitive" ) type confirmationCodePayload struct { AccountRef string `json:"accountRef"` Destination string `json:"destination"` Target string `json:"target"` Code string `json:"code"` } type ConfirmationCodeNotification struct { messaging.Envelope payload confirmationCodePayload } func (ccn *ConfirmationCodeNotification) Serialize() ([]byte, error) { data, err := json.Marshal(ccn.payload) if err != nil { return nil, err } return ccn.Envelope.Wrap(data) } func newConfirmationEvent(action nm.NotificationAction) model.NotificationEvent { return model.NewNotification(mservice.Confirmations, action) } func NewConfirmationCodeEnvelope(sender string, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, code string) messaging.Envelope { return &ConfirmationCodeNotification{ Envelope: messaging.CreateEnvelope(sender, newConfirmationEvent(nm.NAPending)), payload: confirmationCodePayload{ AccountRef: accountRef.Hex(), Destination: destination, Target: string(target), Code: code, }, } }