package notifications import ( gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" "github.com/tech/sendico/pkg/merrors" 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" "google.golang.org/protobuf/proto" ) type DemoRequestNotification struct { messaging.Envelope request *model.DemoRequest } func (drn *DemoRequestNotification) Serialize() ([]byte, error) { if drn.request == nil { return nil, merrors.InvalidArgument("demo request payload is empty", "request") } msg := gmessaging.DemoRequestEvent{ Name: drn.request.Name, OrganizationName: drn.request.OrganizationName, Phone: drn.request.Phone, WorkEmail: drn.request.WorkEmail, PayoutVolume: drn.request.PayoutVolume, Comment: drn.request.Comment, } data, err := proto.Marshal(&msg) if err != nil { return nil, err } return drn.Envelope.Wrap(data) } func NewDemoRequestEvent() model.NotificationEvent { return model.NewNotification(mservice.Site, nm.NACreated) } func NewDemoRequestEnvelope(sender string, request *model.DemoRequest) messaging.Envelope { return &DemoRequestNotification{ Envelope: messaging.CreateEnvelope(sender, NewDemoRequestEvent()), request: request, } } type ContactRequestNotification struct { messaging.Envelope request *model.ContactRequest } func (crn *ContactRequestNotification) Serialize() ([]byte, error) { if crn.request == nil { return nil, merrors.InvalidArgument("contact request payload is empty", "request") } msg := gmessaging.ContactRequestEvent{ Name: crn.request.Name, Email: crn.request.Email, Phone: crn.request.Phone, Company: crn.request.Company, Topic: crn.request.Topic, Message: crn.request.Message, } data, err := proto.Marshal(&msg) if err != nil { return nil, err } return crn.Envelope.Wrap(data) } func NewContactRequestEvent() model.NotificationEvent { return model.NewNotification(mservice.Site, nm.NACreated) } func NewContactRequestEnvelope(sender string, request *model.ContactRequest) messaging.Envelope { return &ContactRequestNotification{ Envelope: messaging.CreateEnvelope(sender, NewContactRequestEvent()), request: request, } }