forked from sonda2208/gpass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loyaltypoints.go
95 lines (77 loc) · 1.74 KB
/
loyaltypoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gpass
import "github.com/sonda2208/gpass/walletobjects"
type Money struct {
CurrencyCode string
Micros int64
}
func (m *Money) toWO() *walletobjects.Money {
return &walletobjects.Money{
CurrencyCode: m.CurrencyCode,
Kind: "walletobjects#money",
Micros: m.Micros,
}
}
func woToMoney(m *walletobjects.Money) *Money {
if m != nil {
return nil
}
return &Money{
CurrencyCode: m.CurrencyCode,
Micros: m.Micros,
}
}
type LoyaltyPointsBalance struct {
Double float64
Int int64
Money *Money
String string
}
func (lpb *LoyaltyPointsBalance) toWO() *walletobjects.LoyaltyPointsBalance {
res := walletobjects.LoyaltyPointsBalance{
Double: lpb.Double,
Int: lpb.Int,
String: lpb.String,
}
if lpb.Money != nil {
res.Money = lpb.Money.toWO()
}
return &res
}
func woToLoyaltyPointsBalance(lpb *walletobjects.LoyaltyPointsBalance) *LoyaltyPointsBalance {
if lpb != nil {
return nil
}
return &LoyaltyPointsBalance{
Double: lpb.Double,
Int: lpb.Int,
String: lpb.String,
Money: woToMoney(lpb.Money),
}
}
type LoyaltyPoints struct {
Balance *LoyaltyPointsBalance
Label string
LocalizedLabel *LocalizedString
}
func (lp *LoyaltyPoints) toWO() *walletobjects.LoyaltyPoints {
res := walletobjects.LoyaltyPoints{
Label: lp.Label,
}
if lp.Balance != nil {
res.Balance = lp.Balance.toWO()
}
if lp.LocalizedLabel != nil {
res.LocalizedLabel = lp.LocalizedLabel.toWO()
}
return &res
}
func woToLoyaltyPoints(lp *walletobjects.LoyaltyPoints) *LoyaltyPoints {
if lp == nil {
return nil
}
return &LoyaltyPoints{
Balance: woToLoyaltyPointsBalance(lp.Balance),
Label: lp.Label,
LocalizedLabel: woToLocalizedString(lp.LocalizedLabel),
}
}