github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_statement_resource.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  // Billing20201105StatementResource Resource contains the running usage of a single resource, including all
    19  // the line items from it.
    20  //
    21  // swagger:model billing_20201105StatementResource
    22  type Billing20201105StatementResource struct {
    23  
    24  	// active_from is the timestamp of when the billed resource became active.
    25  	// Format: date-time
    26  	ActiveFrom strfmt.DateTime `json:"active_from,omitempty"`
    27  
    28  	// active_until is the timestamp of when the billed resource became inactive.
    29  	// Format: date-time
    30  	ActiveUntil strfmt.DateTime `json:"active_until,omitempty"`
    31  
    32  	// amount is the sum of the amount of all line items.
    33  	Amount string `json:"amount,omitempty"`
    34  
    35  	// fcp contains flexible consumption specific properties.
    36  	FlexibleConsumptionMetadata *Billing20201105StatementResourceFlexibleConsumptionMetadata `json:"flexible_consumption_metadata,omitempty"`
    37  
    38  	// line_items is the list of line items as they would appear on an invoice.
    39  	LineItems []*StatementResourceLineItem `json:"line_items"`
    40  
    41  	// resource is a link to the Resource for which this line item charges.
    42  	ResourceLink *LocationLink `json:"resource_link,omitempty"`
    43  }
    44  
    45  // Validate validates this billing 20201105 statement resource
    46  func (m *Billing20201105StatementResource) Validate(formats strfmt.Registry) error {
    47  	var res []error
    48  
    49  	if err := m.validateActiveFrom(formats); err != nil {
    50  		res = append(res, err)
    51  	}
    52  
    53  	if err := m.validateActiveUntil(formats); err != nil {
    54  		res = append(res, err)
    55  	}
    56  
    57  	if err := m.validateFlexibleConsumptionMetadata(formats); err != nil {
    58  		res = append(res, err)
    59  	}
    60  
    61  	if err := m.validateLineItems(formats); err != nil {
    62  		res = append(res, err)
    63  	}
    64  
    65  	if err := m.validateResourceLink(formats); err != nil {
    66  		res = append(res, err)
    67  	}
    68  
    69  	if len(res) > 0 {
    70  		return errors.CompositeValidationError(res...)
    71  	}
    72  	return nil
    73  }
    74  
    75  func (m *Billing20201105StatementResource) validateActiveFrom(formats strfmt.Registry) error {
    76  	if swag.IsZero(m.ActiveFrom) { // not required
    77  		return nil
    78  	}
    79  
    80  	if err := validate.FormatOf("active_from", "body", "date-time", m.ActiveFrom.String(), formats); err != nil {
    81  		return err
    82  	}
    83  
    84  	return nil
    85  }
    86  
    87  func (m *Billing20201105StatementResource) validateActiveUntil(formats strfmt.Registry) error {
    88  	if swag.IsZero(m.ActiveUntil) { // not required
    89  		return nil
    90  	}
    91  
    92  	if err := validate.FormatOf("active_until", "body", "date-time", m.ActiveUntil.String(), formats); err != nil {
    93  		return err
    94  	}
    95  
    96  	return nil
    97  }
    98  
    99  func (m *Billing20201105StatementResource) validateFlexibleConsumptionMetadata(formats strfmt.Registry) error {
   100  	if swag.IsZero(m.FlexibleConsumptionMetadata) { // not required
   101  		return nil
   102  	}
   103  
   104  	if m.FlexibleConsumptionMetadata != nil {
   105  		if err := m.FlexibleConsumptionMetadata.Validate(formats); err != nil {
   106  			if ve, ok := err.(*errors.Validation); ok {
   107  				return ve.ValidateName("flexible_consumption_metadata")
   108  			} else if ce, ok := err.(*errors.CompositeError); ok {
   109  				return ce.ValidateName("flexible_consumption_metadata")
   110  			}
   111  			return err
   112  		}
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  func (m *Billing20201105StatementResource) validateLineItems(formats strfmt.Registry) error {
   119  	if swag.IsZero(m.LineItems) { // not required
   120  		return nil
   121  	}
   122  
   123  	for i := 0; i < len(m.LineItems); i++ {
   124  		if swag.IsZero(m.LineItems[i]) { // not required
   125  			continue
   126  		}
   127  
   128  		if m.LineItems[i] != nil {
   129  			if err := m.LineItems[i].Validate(formats); err != nil {
   130  				if ve, ok := err.(*errors.Validation); ok {
   131  					return ve.ValidateName("line_items" + "." + strconv.Itoa(i))
   132  				} else if ce, ok := err.(*errors.CompositeError); ok {
   133  					return ce.ValidateName("line_items" + "." + strconv.Itoa(i))
   134  				}
   135  				return err
   136  			}
   137  		}
   138  
   139  	}
   140  
   141  	return nil
   142  }
   143  
   144  func (m *Billing20201105StatementResource) validateResourceLink(formats strfmt.Registry) error {
   145  	if swag.IsZero(m.ResourceLink) { // not required
   146  		return nil
   147  	}
   148  
   149  	if m.ResourceLink != nil {
   150  		if err := m.ResourceLink.Validate(formats); err != nil {
   151  			if ve, ok := err.(*errors.Validation); ok {
   152  				return ve.ValidateName("resource_link")
   153  			} else if ce, ok := err.(*errors.CompositeError); ok {
   154  				return ce.ValidateName("resource_link")
   155  			}
   156  			return err
   157  		}
   158  	}
   159  
   160  	return nil
   161  }
   162  
   163  // ContextValidate validate this billing 20201105 statement resource based on the context it is used
   164  func (m *Billing20201105StatementResource) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   165  	var res []error
   166  
   167  	if err := m.contextValidateFlexibleConsumptionMetadata(ctx, formats); err != nil {
   168  		res = append(res, err)
   169  	}
   170  
   171  	if err := m.contextValidateLineItems(ctx, formats); err != nil {
   172  		res = append(res, err)
   173  	}
   174  
   175  	if err := m.contextValidateResourceLink(ctx, formats); err != nil {
   176  		res = append(res, err)
   177  	}
   178  
   179  	if len(res) > 0 {
   180  		return errors.CompositeValidationError(res...)
   181  	}
   182  	return nil
   183  }
   184  
   185  func (m *Billing20201105StatementResource) contextValidateFlexibleConsumptionMetadata(ctx context.Context, formats strfmt.Registry) error {
   186  
   187  	if m.FlexibleConsumptionMetadata != nil {
   188  		if err := m.FlexibleConsumptionMetadata.ContextValidate(ctx, formats); err != nil {
   189  			if ve, ok := err.(*errors.Validation); ok {
   190  				return ve.ValidateName("flexible_consumption_metadata")
   191  			} else if ce, ok := err.(*errors.CompositeError); ok {
   192  				return ce.ValidateName("flexible_consumption_metadata")
   193  			}
   194  			return err
   195  		}
   196  	}
   197  
   198  	return nil
   199  }
   200  
   201  func (m *Billing20201105StatementResource) contextValidateLineItems(ctx context.Context, formats strfmt.Registry) error {
   202  
   203  	for i := 0; i < len(m.LineItems); i++ {
   204  
   205  		if m.LineItems[i] != nil {
   206  			if err := m.LineItems[i].ContextValidate(ctx, formats); err != nil {
   207  				if ve, ok := err.(*errors.Validation); ok {
   208  					return ve.ValidateName("line_items" + "." + strconv.Itoa(i))
   209  				} else if ce, ok := err.(*errors.CompositeError); ok {
   210  					return ce.ValidateName("line_items" + "." + strconv.Itoa(i))
   211  				}
   212  				return err
   213  			}
   214  		}
   215  
   216  	}
   217  
   218  	return nil
   219  }
   220  
   221  func (m *Billing20201105StatementResource) contextValidateResourceLink(ctx context.Context, formats strfmt.Registry) error {
   222  
   223  	if m.ResourceLink != nil {
   224  		if err := m.ResourceLink.ContextValidate(ctx, formats); err != nil {
   225  			if ve, ok := err.(*errors.Validation); ok {
   226  				return ve.ValidateName("resource_link")
   227  			} else if ce, ok := err.(*errors.CompositeError); ok {
   228  				return ce.ValidateName("resource_link")
   229  			}
   230  			return err
   231  		}
   232  	}
   233  
   234  	return nil
   235  }
   236  
   237  // MarshalBinary interface implementation
   238  func (m *Billing20201105StatementResource) MarshalBinary() ([]byte, error) {
   239  	if m == nil {
   240  		return nil, nil
   241  	}
   242  	return swag.WriteJSON(m)
   243  }
   244  
   245  // UnmarshalBinary interface implementation
   246  func (m *Billing20201105StatementResource) UnmarshalBinary(b []byte) error {
   247  	var res Billing20201105StatementResource
   248  	if err := swag.ReadJSON(b, &res); err != nil {
   249  		return err
   250  	}
   251  	*m = res
   252  	return nil
   253  }