154 lines
4.3 KiB
Go
154 lines
4.3 KiB
Go
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const SCUMRewardDeliverCommandType = "reward.deliver"
|
|
const SCUMGiftNotificationCommandType = "player.notify"
|
|
|
|
type SCUMGiftItemDefinition struct {
|
|
Key string
|
|
Label string
|
|
MaximumQuantity int
|
|
}
|
|
type SCUMGiftItemCatalog struct {
|
|
GameVersion string
|
|
Items []SCUMGiftItemDefinition
|
|
}
|
|
|
|
func ParseSCUMGiftItemCatalog(content string) (SCUMGiftItemCatalog, bool) {
|
|
var catalog struct {
|
|
GameVersion string `json:"gameVersion"`
|
|
Items []struct {
|
|
Key string `json:"key"`
|
|
Label string `json:"label"`
|
|
MaximumQuantity int `json:"maximumQuantity"`
|
|
} `json:"items"`
|
|
}
|
|
if json.Unmarshal([]byte(content), &catalog) != nil || strings.TrimSpace(catalog.GameVersion) == "" || len(catalog.Items) == 0 {
|
|
return SCUMGiftItemCatalog{}, false
|
|
}
|
|
result := SCUMGiftItemCatalog{GameVersion: catalog.GameVersion, Items: make([]SCUMGiftItemDefinition, 0, len(catalog.Items))}
|
|
seen := map[string]struct{}{}
|
|
for _, item := range catalog.Items {
|
|
if strings.TrimSpace(item.Key) == "" || strings.TrimSpace(item.Label) == "" || item.MaximumQuantity < 1 {
|
|
return SCUMGiftItemCatalog{}, false
|
|
}
|
|
if _, ok := seen[item.Key]; ok {
|
|
return SCUMGiftItemCatalog{}, false
|
|
}
|
|
seen[item.Key] = struct{}{}
|
|
result.Items = append(result.Items, SCUMGiftItemDefinition{Key: item.Key, Label: item.Label, MaximumQuantity: item.MaximumQuantity})
|
|
}
|
|
return result, true
|
|
}
|
|
|
|
type GameGiftItem struct {
|
|
CatalogItemKey string
|
|
Label string
|
|
Quantity int
|
|
}
|
|
type GameGiftCatalog struct {
|
|
ID string
|
|
ServerInstanceID string
|
|
Name string
|
|
GameVersion string
|
|
DraftItems []GameGiftItem
|
|
LatestRevisionID string
|
|
CreatedBy string
|
|
UpdatedAt time.Time
|
|
CreatedAt time.Time
|
|
}
|
|
type GameGiftRevision struct {
|
|
ID string
|
|
CatalogID string
|
|
ServerInstanceID string
|
|
Revision int
|
|
GameVersion string
|
|
Items []GameGiftItem
|
|
PublishedBy string
|
|
PublishedAt time.Time
|
|
}
|
|
type GameGiftGrantStatus string
|
|
|
|
const (
|
|
GameGiftGrantPendingApproval GameGiftGrantStatus = "pending-approval"
|
|
GameGiftGrantQueued GameGiftGrantStatus = "queued"
|
|
GameGiftGrantDelivered GameGiftGrantStatus = "delivered"
|
|
GameGiftGrantNotificationFailed GameGiftGrantStatus = "notification_failed"
|
|
GameGiftGrantFailed GameGiftGrantStatus = "failed"
|
|
GameGiftGrantUnknown GameGiftGrantStatus = "unknown"
|
|
)
|
|
|
|
type GameGiftGrant struct {
|
|
ID string
|
|
ServerInstanceID string
|
|
CatalogID string
|
|
RevisionID string
|
|
RevisionNumber int
|
|
GameVersion string
|
|
Items []GameGiftItem
|
|
GamePlayerRecordID string
|
|
GamePlayerID string
|
|
PlayerDisplayName string
|
|
Notice string
|
|
IdempotencyKey string
|
|
RequesterID string
|
|
ApproverID string
|
|
Status GameGiftGrantStatus
|
|
DeliveryCommandID string
|
|
NotificationCommandID string
|
|
DeliverySummary string
|
|
NotificationSummary string
|
|
CreatedAt time.Time
|
|
ApprovedAt time.Time
|
|
CompletedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
type GameGiftCatalogFilter struct {
|
|
ServerInstanceID string
|
|
Limit int
|
|
}
|
|
type GameGiftRevisionFilter struct {
|
|
CatalogID string
|
|
ServerInstanceID string
|
|
Limit int
|
|
}
|
|
type GameGiftGrantFilter struct {
|
|
ServerInstanceID string
|
|
GamePlayerRecordID string
|
|
IdempotencyKey string
|
|
Limit int
|
|
}
|
|
type GameGiftCatalogRequest struct {
|
|
ID string
|
|
Name string
|
|
GameVersion string
|
|
Items []GameGiftItem
|
|
}
|
|
type GameGiftGrantRequest struct {
|
|
RevisionID string
|
|
GamePlayerRecordID string
|
|
Notice string
|
|
IdempotencyKey string
|
|
}
|
|
|
|
func CopyGameGiftItems(items []GameGiftItem) []GameGiftItem {
|
|
return append([]GameGiftItem(nil), items...)
|
|
}
|
|
func CopyGameGiftCatalog(value GameGiftCatalog) GameGiftCatalog {
|
|
value.DraftItems = CopyGameGiftItems(value.DraftItems)
|
|
return value
|
|
}
|
|
func CopyGameGiftRevision(value GameGiftRevision) GameGiftRevision {
|
|
value.Items = CopyGameGiftItems(value.Items)
|
|
return value
|
|
}
|
|
func CopyGameGiftGrant(value GameGiftGrant) GameGiftGrant {
|
|
value.Items = CopyGameGiftItems(value.Items)
|
|
return value
|
|
}
|