github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_statement.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package models 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "context" 10 "strconv" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Billing20201105Statement RunningUsage describes the usage that accrued during a specific 19 // billing period. 20 // 21 // swagger:model billing_20201105Statement 22 type Billing20201105Statement struct { 23 24 // billing_period_end is the end time of the period that was considered for 25 // this usage calculation. 26 // Format: date-time 27 BillingPeriodEnd strfmt.DateTime `json:"billing_period_end,omitempty"` 28 29 // billing_period_start is the start time of the period that was considered 30 // for this usage calculation. 31 // Format: date-time 32 BillingPeriodStart strfmt.DateTime `json:"billing_period_start,omitempty"` 33 34 // fcp contains flexible consumption specific properties. 35 FlexibleConsumptionMetadata *Billing20201105StatementFlexibleConsumptionMetadata `json:"flexible_consumption_metadata,omitempty"` 36 37 // id is the id associated with the statement. 38 ID string `json:"id,omitempty"` 39 40 // last_updated_at is the last time this statement gets updated. 41 // This shows the last usage time that is included in this statement. 42 // Format: date-time 43 LastUpdatedAt strfmt.DateTime `json:"last_updated_at,omitempty"` 44 45 // on_demand contains pay-as-you-go specific properties. 46 OnDemandMetadata *Billing20201105StatementOnDemandMetadata `json:"on_demand_metadata,omitempty"` 47 48 // resources has information about each resource that is part of the statement. 49 Resources []*Billing20201105StatementResource `json:"resources"` 50 51 // total is the cost produced within this billing period minus any 52 // discount that is granted because of a positive account balance. This 53 // should be considered an estimate because not all information required to 54 // issue an invoice might have been taken into consideration (e.g. billing 55 // address country and tax might not be reflected in this value). 56 Total string `json:"total,omitempty"` 57 } 58 59 // Validate validates this billing 20201105 statement 60 func (m *Billing20201105Statement) Validate(formats strfmt.Registry) error { 61 var res []error 62 63 if err := m.validateBillingPeriodEnd(formats); err != nil { 64 res = append(res, err) 65 } 66 67 if err := m.validateBillingPeriodStart(formats); err != nil { 68 res = append(res, err) 69 } 70 71 if err := m.validateFlexibleConsumptionMetadata(formats); err != nil { 72 res = append(res, err) 73 } 74 75 if err := m.validateLastUpdatedAt(formats); err != nil { 76 res = append(res, err) 77 } 78 79 if err := m.validateOnDemandMetadata(formats); err != nil { 80 res = append(res, err) 81 } 82 83 if err := m.validateResources(formats); err != nil { 84 res = append(res, err) 85 } 86 87 if len(res) > 0 { 88 return errors.CompositeValidationError(res...) 89 } 90 return nil 91 } 92 93 func (m *Billing20201105Statement) validateBillingPeriodEnd(formats strfmt.Registry) error { 94 if swag.IsZero(m.BillingPeriodEnd) { // not required 95 return nil 96 } 97 98 if err := validate.FormatOf("billing_period_end", "body", "date-time", m.BillingPeriodEnd.String(), formats); err != nil { 99 return err 100 } 101 102 return nil 103 } 104 105 func (m *Billing20201105Statement) validateBillingPeriodStart(formats strfmt.Registry) error { 106 if swag.IsZero(m.BillingPeriodStart) { // not required 107 return nil 108 } 109 110 if err := validate.FormatOf("billing_period_start", "body", "date-time", m.BillingPeriodStart.String(), formats); err != nil { 111 return err 112 } 113 114 return nil 115 } 116 117 func (m *Billing20201105Statement) validateFlexibleConsumptionMetadata(formats strfmt.Registry) error { 118 if swag.IsZero(m.FlexibleConsumptionMetadata) { // not required 119 return nil 120 } 121 122 if m.FlexibleConsumptionMetadata != nil { 123 if err := m.FlexibleConsumptionMetadata.Validate(formats); err != nil { 124 if ve, ok := err.(*errors.Validation); ok { 125 return ve.ValidateName("flexible_consumption_metadata") 126 } else if ce, ok := err.(*errors.CompositeError); ok { 127 return ce.ValidateName("flexible_consumption_metadata") 128 } 129 return err 130 } 131 } 132 133 return nil 134 } 135 136 func (m *Billing20201105Statement) validateLastUpdatedAt(formats strfmt.Registry) error { 137 if swag.IsZero(m.LastUpdatedAt) { // not required 138 return nil 139 } 140 141 if err := validate.FormatOf("last_updated_at", "body", "date-time", m.LastUpdatedAt.String(), formats); err != nil { 142 return err 143 } 144 145 return nil 146 } 147 148 func (m *Billing20201105Statement) validateOnDemandMetadata(formats strfmt.Registry) error { 149 if swag.IsZero(m.OnDemandMetadata) { // not required 150 return nil 151 } 152 153 if m.OnDemandMetadata != nil { 154 if err := m.OnDemandMetadata.Validate(formats); err != nil { 155 if ve, ok := err.(*errors.Validation); ok { 156 return ve.ValidateName("on_demand_metadata") 157 } else if ce, ok := err.(*errors.CompositeError); ok { 158 return ce.ValidateName("on_demand_metadata") 159 } 160 return err 161 } 162 } 163 164 return nil 165 } 166 167 func (m *Billing20201105Statement) validateResources(formats strfmt.Registry) error { 168 if swag.IsZero(m.Resources) { // not required 169 return nil 170 } 171 172 for i := 0; i < len(m.Resources); i++ { 173 if swag.IsZero(m.Resources[i]) { // not required 174 continue 175 } 176 177 if m.Resources[i] != nil { 178 if err := m.Resources[i].Validate(formats); err != nil { 179 if ve, ok := err.(*errors.Validation); ok { 180 return ve.ValidateName("resources" + "." + strconv.Itoa(i)) 181 } else if ce, ok := err.(*errors.CompositeError); ok { 182 return ce.ValidateName("resources" + "." + strconv.Itoa(i)) 183 } 184 return err 185 } 186 } 187 188 } 189 190 return nil 191 } 192 193 // ContextValidate validate this billing 20201105 statement based on the context it is used 194 func (m *Billing20201105Statement) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 195 var res []error 196 197 if err := m.contextValidateFlexibleConsumptionMetadata(ctx, formats); err != nil { 198 res = append(res, err) 199 } 200 201 if err := m.contextValidateOnDemandMetadata(ctx, formats); err != nil { 202 res = append(res, err) 203 } 204 205 if err := m.contextValidateResources(ctx, formats); err != nil { 206 res = append(res, err) 207 } 208 209 if len(res) > 0 { 210 return errors.CompositeValidationError(res...) 211 } 212 return nil 213 } 214 215 func (m *Billing20201105Statement) contextValidateFlexibleConsumptionMetadata(ctx context.Context, formats strfmt.Registry) error { 216 217 if m.FlexibleConsumptionMetadata != nil { 218 if err := m.FlexibleConsumptionMetadata.ContextValidate(ctx, formats); err != nil { 219 if ve, ok := err.(*errors.Validation); ok { 220 return ve.ValidateName("flexible_consumption_metadata") 221 } else if ce, ok := err.(*errors.CompositeError); ok { 222 return ce.ValidateName("flexible_consumption_metadata") 223 } 224 return err 225 } 226 } 227 228 return nil 229 } 230 231 func (m *Billing20201105Statement) contextValidateOnDemandMetadata(ctx context.Context, formats strfmt.Registry) error { 232 233 if m.OnDemandMetadata != nil { 234 if err := m.OnDemandMetadata.ContextValidate(ctx, formats); err != nil { 235 if ve, ok := err.(*errors.Validation); ok { 236 return ve.ValidateName("on_demand_metadata") 237 } else if ce, ok := err.(*errors.CompositeError); ok { 238 return ce.ValidateName("on_demand_metadata") 239 } 240 return err 241 } 242 } 243 244 return nil 245 } 246 247 func (m *Billing20201105Statement) contextValidateResources(ctx context.Context, formats strfmt.Registry) error { 248 249 for i := 0; i < len(m.Resources); i++ { 250 251 if m.Resources[i] != nil { 252 if err := m.Resources[i].ContextValidate(ctx, formats); err != nil { 253 if ve, ok := err.(*errors.Validation); ok { 254 return ve.ValidateName("resources" + "." + strconv.Itoa(i)) 255 } else if ce, ok := err.(*errors.CompositeError); ok { 256 return ce.ValidateName("resources" + "." + strconv.Itoa(i)) 257 } 258 return err 259 } 260 } 261 262 } 263 264 return nil 265 } 266 267 // MarshalBinary interface implementation 268 func (m *Billing20201105Statement) MarshalBinary() ([]byte, error) { 269 if m == nil { 270 return nil, nil 271 } 272 return swag.WriteJSON(m) 273 } 274 275 // UnmarshalBinary interface implementation 276 func (m *Billing20201105Statement) UnmarshalBinary(b []byte) error { 277 var res Billing20201105Statement 278 if err := swag.ReadJSON(b, &res); err != nil { 279 return err 280 } 281 *m = res 282 return nil 283 }