forked from vickxxx/appstore
-
Notifications
You must be signed in to change notification settings - Fork 3
/
finances_filters.go
80 lines (68 loc) · 2.62 KB
/
finances_filters.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
package appstore
import (
"fmt"
"time"
)
//FinancesReportType type
type FinancesReportType string
const (
//FinancesReportTypeFinancial const
FinancesReportTypeFinancial FinancesReportType = "FINANCIAL"
//FinancesReportTypeFinanceDetail const
FinancesReportTypeFinanceDetail FinancesReportType = "FINANCE_DETAIL"
)
//FinancesReportsFilter sales reports filter
type FinancesReportsFilter struct {
ReportDate time.Time //(Required) The fiscal month of the report you wish to download based on the Apple Fiscal Calendar. The fiscal month is specified in the YYYY-MM format.
ReportType FinancesReportType //(Required) This value is always FINANCIAL. Possible values: FINANCIAL, FINANCE_DETAIL
RegionCode string //(Required) You can download consolidated or separate financial reports per territory. For a complete list of possible values, see Financial Report Regions and Currencies.
}
//SetReportType Set report type
func (f *FinancesReportsFilter) SetReportType(value FinancesReportType) *FinancesReportsFilter {
f.ReportType = value
return f
}
//SetReportDate Set report date
func (f *FinancesReportsFilter) SetReportDate(value time.Time) *FinancesReportsFilter {
f.ReportDate = value
return f
}
//SetRegionCode Set report date
func (f *FinancesReportsFilter) SetRegionCode(value string) *FinancesReportsFilter {
f.RegionCode = value
return f
}
//TypeFinancial Change report type to Financial
func (f *FinancesReportsFilter) TypeFinancial() *FinancesReportsFilter {
return f.SetReportType(FinancesReportTypeFinancial)
}
//TypeFinanceDetail Change report type to Sales
func (f *FinancesReportsFilter) TypeFinanceDetail() *FinancesReportsFilter {
return f.SetReportType(FinancesReportTypeFinanceDetail)
}
//ToQueryParamsMap Convert filter to query params
func (f *FinancesReportsFilter) toQueryParamsMap() map[string]interface{} {
qs := make(map[string]interface{})
qs["filter[reportType]"] = string(f.ReportType)
qs["filter[regionCode]"] = f.RegionCode
if !f.ReportDate.IsZero() {
qs["filter[reportDate]"] = f.ReportDate.Format("2006-01")
}
return qs
}
//IsValid Validate sales report filter params
func (f *FinancesReportsFilter) IsValid() error {
if f.ReportType == "" {
return fmt.Errorf("FinancesReportsFilter.IsValid: %v", "ReportType is required")
}
if f.RegionCode == "" {
return fmt.Errorf("FinancesReportsFilter.IsValid: %v", "RegionCode is required")
}
if f.ReportDate.IsZero() {
return fmt.Errorf("FinancesReportsFilter.IsValid: %v", "ReportDate is required")
}
return nil
}
func NewFinancesReportsFilter() *FinancesReportsFilter {
return &FinancesReportsFilter{ReportType: FinancesReportTypeFinancial}
}