1package hcloud
2
3import (
4	"context"
5
6	"github.com/hetznercloud/hcloud-go/hcloud/schema"
7)
8
9// Pricing specifies pricing information for various resources.
10type Pricing struct {
11	Image             ImagePricing
12	FloatingIP        FloatingIPPricing
13	FloatingIPs       []FloatingIPTypePricing
14	Traffic           TrafficPricing
15	ServerBackup      ServerBackupPricing
16	ServerTypes       []ServerTypePricing
17	LoadBalancerTypes []LoadBalancerTypePricing
18	Volume            VolumePricing
19}
20
21// Price represents a price. Net amount, gross amount, as well as VAT rate are
22// specified as strings and it is the user's responsibility to convert them to
23// appropriate types for calculations.
24type Price struct {
25	Currency string
26	VATRate  string
27	Net      string
28	Gross    string
29}
30
31// ImagePricing provides pricing information for imaegs.
32type ImagePricing struct {
33	PerGBMonth Price
34}
35
36// FloatingIPPricing provides pricing information for Floating IPs.
37type FloatingIPPricing struct {
38	Monthly Price
39}
40
41// FloatingIPTypePricing provides pricing information for Floating IPs per Type.
42type FloatingIPTypePricing struct {
43	Type     FloatingIPType
44	Pricings []FloatingIPTypeLocationPricing
45}
46
47// FloatingIPTypeLocationPricing provides pricing information for a Floating IP type
48// at a location.
49type FloatingIPTypeLocationPricing struct {
50	Location *Location
51	Monthly  Price
52}
53
54// TrafficPricing provides pricing information for traffic.
55type TrafficPricing struct {
56	PerTB Price
57}
58
59// VolumePricing provides pricing information for a Volume.
60type VolumePricing struct {
61	PerGBMonthly Price
62}
63
64// ServerBackupPricing provides pricing information for server backups.
65type ServerBackupPricing struct {
66	Percentage string
67}
68
69// ServerTypePricing provides pricing information for a server type.
70type ServerTypePricing struct {
71	ServerType *ServerType
72	Pricings   []ServerTypeLocationPricing
73}
74
75// ServerTypeLocationPricing provides pricing information for a server type
76// at a location.
77type ServerTypeLocationPricing struct {
78	Location *Location
79	Hourly   Price
80	Monthly  Price
81}
82
83// LoadBalancerTypePricing provides pricing information for a Load Balancer type.
84type LoadBalancerTypePricing struct {
85	LoadBalancerType *LoadBalancerType
86	Pricings         []LoadBalancerTypeLocationPricing
87}
88
89// LoadBalancerTypeLocationPricing provides pricing information for a Load Balancer type
90// at a location.
91type LoadBalancerTypeLocationPricing struct {
92	Location *Location
93	Hourly   Price
94	Monthly  Price
95}
96
97// PricingClient is a client for the pricing API.
98type PricingClient struct {
99	client *Client
100}
101
102// Get retrieves pricing information.
103func (c *PricingClient) Get(ctx context.Context) (Pricing, *Response, error) {
104	req, err := c.client.NewRequest(ctx, "GET", "/pricing", nil)
105	if err != nil {
106		return Pricing{}, nil, err
107	}
108
109	var body schema.PricingGetResponse
110	resp, err := c.client.Do(req, &body)
111	if err != nil {
112		return Pricing{}, nil, err
113	}
114	return PricingFromSchema(body.Pricing), resp, nil
115}
116