package dto import ( "encoding/json" ) type PayloadAction uint8 const ( PayloadActionNext = iota PayloadActionPrevious PayloadActionAddMember PayloadActionRemoveMember PayloadActionYesNo PayloadActionVote ) type QuestionType uint8 const ( QuestionTypeChatMembers QuestionType = iota QuestionTypeRedmine QuestionTypeRedmineHours ) type Payload struct { User int64 `json:"u,omitempty"` Chat int64 `json:"c,omitempty"` Action PayloadAction `json:"a"` Data json.RawMessage `json:"d,omitempty"` } type Member struct { ID int64 Name string } type Vote struct { Vote float32 `json:"v"` } type Answer struct { Type QuestionType `json:"t"` Result bool `json:"r"` } func NewNextPageMembersPayload(userID, chatID int64) *Payload { return &Payload{ Action: PayloadActionNext, User: userID, Chat: chatID, } } func NewPrevPageMembersPayload(userID, chatID int64) *Payload { return &Payload{ Action: PayloadActionPrevious, User: userID, Chat: chatID, } } func NewAddMemberPayload(userID, chatID, memberID int64, memberName string) *Payload { return &Payload{ Action: PayloadActionAddMember, User: userID, Chat: chatID, Data: marshal(Member{ID: memberID, Name: memberName}), } } func NewRemoveMemberPayload(userID, chatID, memberID int64, memberName string) *Payload { return &Payload{ Action: PayloadActionRemoveMember, User: userID, Chat: chatID, Data: marshal(Member{ID: memberID, Name: memberName}), } } func NewVotePayload(chatID int64, vote float32) *Payload { return &Payload{ Action: PayloadActionVote, Chat: chatID, Data: marshal(Vote{Vote: vote}), } } func NewConfirmMembersPayload(userID int64, chatID int64) *Payload { return &Payload{ Action: PayloadActionYesNo, User: userID, Chat: chatID, Data: marshal(Answer{Type: QuestionTypeChatMembers, Result: true}), } } func NewRedmineQuestionPayload(userID int64, chatID int64, isYes bool) *Payload { return &Payload{ Action: PayloadActionYesNo, User: userID, Chat: chatID, Data: marshal(Answer{Type: QuestionTypeRedmine, Result: isYes}), } } func NewRedmineHoursQuestionPayload(userID int64, chatID int64, isYes bool) *Payload { return &Payload{ Action: PayloadActionYesNo, User: userID, Chat: chatID, Data: marshal(Answer{Type: QuestionTypeRedmineHours, Result: isYes}), } } func marshal(val interface{}) json.RawMessage { data, _ := json.Marshal(val) return data }