github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_resource_usage.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  // Billing20201105ResourceUsage ResourceUsage contains the usage of a single resource, including all
    19  // the line items from it.
    20  //
    21  // swagger:model billing_20201105ResourceUsage
    22  type Billing20201105ResourceUsage struct {
    23  
    24  	// amount is the sum of the amount of all line items.
    25  	Amount string `json:"amount,omitempty"`
    26  
    27  	// line_items is the list of line items as they would appear on an invoice.
    28  	// They are a simplified version of the backend one, containing only
    29  	// points useful for the UI.
    30  	LineItems []*Billing20201105InvoiceLineItem `json:"line_items"`
    31  
    32  	// resource is a link to the Resource for which this line item charges.
    33  	Resource *LocationLink `json:"resource,omitempty"`
    34  
    35  	// total_Hours contains the difference between usage_until and usage_from
    36  	// in units of hours.
    37  	TotalHours float64 `json:"total_hours,omitempty"`
    38  
    39  	// usage_from is the start time of the first line item of this resource.
    40  	// Format: date-time
    41  	UsageFrom strfmt.DateTime `json:"usage_from,omitempty"`
    42  
    43  	// usage_until is the end time of the last line item of this resource.
    44  	// Format: date-time
    45  	UsageUntil strfmt.DateTime `json:"usage_until,omitempty"`
    46  }
    47  
    48  // Validate validates this billing 20201105 resource usage
    49  func (m *Billing20201105ResourceUsage) Validate(formats strfmt.Registry) error {
    50  	var res []error
    51  
    52  	if err := m.validateLineItems(formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  
    56  	if err := m.validateResource(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if err := m.validateUsageFrom(formats); err != nil {
    61  		res = append(res, err)
    62  	}
    63  
    64  	if err := m.validateUsageUntil(formats); err != nil {
    65  		res = append(res, err)
    66  	}
    67  
    68  	if len(res) > 0 {
    69  		return errors.CompositeValidationError(res...)
    70  	}
    71  	return nil
    72  }
    73  
    74  func (m *Billing20201105ResourceUsage) validateLineItems(formats strfmt.Registry) error {
    75  	if swag.IsZero(m.LineItems) { // not required
    76  		return nil
    77  	}
    78  
    79  	for i := 0; i < len(m.LineItems); i++ {
    80  		if swag.IsZero(m.LineItems[i]) { // not required
    81  			continue
    82  		}
    83  
    84  		if m.LineItems[i] != nil {
    85  			if err := m.LineItems[i].Validate(formats); err != nil {
    86  				if ve, ok := err.(*errors.Validation); ok {
    87  					return ve.ValidateName("line_items" + "." + strconv.Itoa(i))
    88  				} else if ce, ok := err.(*errors.CompositeError); ok {
    89  					return ce.ValidateName("line_items" + "." + strconv.Itoa(i))
    90  				}
    91  				return err
    92  			}
    93  		}
    94  
    95  	}
    96  
    97  	return nil
    98  }
    99  
   100  func (m *Billing20201105ResourceUsage) validateResource(formats strfmt.Registry) error {
   101  	if swag.IsZero(m.Resource) { // not required
   102  		return nil
   103  	}
   104  
   105  	if m.Resource != nil {
   106  		if err := m.Resource.Validate(formats); err != nil {
   107  			if ve, ok := err.(*errors.Validation); ok {
   108  				return ve.ValidateName("resource")
   109  			} else if ce, ok := err.(*errors.CompositeError); ok {
   110  				return ce.ValidateName("resource")
   111  			}
   112  			return err
   113  		}
   114  	}
   115  
   116  	return nil
   117  }
   118  
   119  func (m *Billing20201105ResourceUsage) validateUsageFrom(formats strfmt.Registry) error {
   120  	if swag.IsZero(m.UsageFrom) { // not required
   121  		return nil
   122  	}
   123  
   124  	if err := validate.FormatOf("usage_from", "body", "date-time", m.UsageFrom.String(), formats); err != nil {
   125  		return err
   126  	}
   127  
   128  	return nil
   129  }
   130  
   131  func (m *Billing20201105ResourceUsage) validateUsageUntil(formats strfmt.Registry) error {
   132  	if swag.IsZero(m.UsageUntil) { // not required
   133  		return nil
   134  	}
   135  
   136  	if err := validate.FormatOf("usage_until", "body", "date-time", m.UsageUntil.String(), formats); err != nil {
   137  		return err
   138  	}
   139  
   140  	return nil
   141  }
   142  
   143  // ContextValidate validate this billing 20201105 resource usage based on the context it is used
   144  func (m *Billing20201105ResourceUsage) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   145  	var res []error
   146  
   147  	if err := m.contextValidateLineItems(ctx, formats); err != nil {
   148  		res = append(res, err)
   149  	}
   150  
   151  	if err := m.contextValidateResource(ctx, formats); err != nil {
   152  		res = append(res, err)
   153  	}
   154  
   155  	if len(res) > 0 {
   156  		return errors.CompositeValidationError(res...)
   157  	}
   158  	return nil
   159  }
   160  
   161  func (m *Billing20201105ResourceUsage) contextValidateLineItems(ctx context.Context, formats strfmt.Registry) error {
   162  
   163  	for i := 0; i < len(m.LineItems); i++ {
   164  
   165  		if m.LineItems[i] != nil {
   166  			if err := m.LineItems[i].ContextValidate(ctx, formats); err != nil {
   167  				if ve, ok := err.(*errors.Validation); ok {
   168  					return ve.ValidateName("line_items" + "." + strconv.Itoa(i))
   169  				} else if ce, ok := err.(*errors.CompositeError); ok {
   170  					return ce.ValidateName("line_items" + "." + strconv.Itoa(i))
   171  				}
   172  				return err
   173  			}
   174  		}
   175  
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  func (m *Billing20201105ResourceUsage) contextValidateResource(ctx context.Context, formats strfmt.Registry) error {
   182  
   183  	if m.Resource != nil {
   184  		if err := m.Resource.ContextValidate(ctx, formats); err != nil {
   185  			if ve, ok := err.(*errors.Validation); ok {
   186  				return ve.ValidateName("resource")
   187  			} else if ce, ok := err.(*errors.CompositeError); ok {
   188  				return ce.ValidateName("resource")
   189  			}
   190  			return err
   191  		}
   192  	}
   193  
   194  	return nil
   195  }
   196  
   197  // MarshalBinary interface implementation
   198  func (m *Billing20201105ResourceUsage) MarshalBinary() ([]byte, error) {
   199  	if m == nil {
   200  		return nil, nil
   201  	}
   202  	return swag.WriteJSON(m)
   203  }
   204  
   205  // UnmarshalBinary interface implementation
   206  func (m *Billing20201105ResourceUsage) UnmarshalBinary(b []byte) error {
   207  	var res Billing20201105ResourceUsage
   208  	if err := swag.ReadJSON(b, &res); err != nil {
   209  		return err
   210  	}
   211  	*m = res
   212  	return nil
   213  }