github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_consumption_pool.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  // Billing20201105ConsumptionPool ConsumptionPool represents a FCP Consumption Pool
    19  //
    20  // swagger:model billing_20201105ConsumptionPool
    21  type Billing20201105ConsumptionPool struct {
    22  
    23  	// active_from is the timestamp of when the consumption pool became active.
    24  	// Format: date-time
    25  	ActiveFrom strfmt.DateTime `json:"active_from,omitempty"`
    26  
    27  	// active_until is the timestamp of when the consumption pool became inactive.
    28  	// Format: date-time
    29  	ActiveUntil strfmt.DateTime `json:"active_until,omitempty"`
    30  
    31  	// billing_account_id is the slug ID of the Billing Account this
    32  	// consumption pool is belongs to.
    33  	BillingAccountID string `json:"billing_account_id,omitempty"`
    34  
    35  	// created_at is the time when consumption pool has been created.
    36  	// Format: date-time
    37  	CreatedAt strfmt.DateTime `json:"created_at,omitempty"`
    38  
    39  	// discounts is the list of discounts associated with the consumption pool.
    40  	Discounts []*Billing20201105Discount `json:"discounts"`
    41  
    42  	// id is the id associated with the consumption pool.
    43  	ID string `json:"id,omitempty"`
    44  
    45  	// initial_amount is the initial amount on the consumption pool in USD.
    46  	InitialAmount string `json:"initial_amount,omitempty"`
    47  
    48  	// organization_id is the organization where the billing account belongs to.
    49  	OrganizationID string `json:"organization_id,omitempty"`
    50  
    51  	// recognized_balance is the official remaining balance of this consumption pool in USD
    52  	// as of the last recognition event.
    53  	RecognizedBalance string `json:"recognized_balance,omitempty"`
    54  
    55  	// running_total is a running usage estimate since the last recognition event.
    56  	// This number will be increased after each new running transaction and
    57  	// zeroed after a recognition event (if recognition event covered all available running
    58  	// transactions)
    59  	RunningTotal string `json:"running_total,omitempty"`
    60  
    61  	// status is the current status of the consumption pool (ex. active, upcoming, rolled over, expired).
    62  	Status *Billing20201105ConsumptionPoolStatus `json:"status,omitempty"`
    63  
    64  	// support_level is the support level associated with the consumption pool.
    65  	SupportLevel string `json:"support_level,omitempty"`
    66  
    67  	// support_levels is the list of products and their corresponding support levels for the associated consumption pool
    68  	SupportLevels []*Billing20201105SupportLevel `json:"support_levels"`
    69  
    70  	// updated_at is the last time the consumption pool has been updated.
    71  	// Format: date-time
    72  	UpdatedAt strfmt.DateTime `json:"updated_at,omitempty"`
    73  }
    74  
    75  // Validate validates this billing 20201105 consumption pool
    76  func (m *Billing20201105ConsumptionPool) Validate(formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.validateActiveFrom(formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if err := m.validateActiveUntil(formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	if err := m.validateCreatedAt(formats); err != nil {
    88  		res = append(res, err)
    89  	}
    90  
    91  	if err := m.validateDiscounts(formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if err := m.validateStatus(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if err := m.validateSupportLevels(formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := m.validateUpdatedAt(formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if len(res) > 0 {
   108  		return errors.CompositeValidationError(res...)
   109  	}
   110  	return nil
   111  }
   112  
   113  func (m *Billing20201105ConsumptionPool) validateActiveFrom(formats strfmt.Registry) error {
   114  	if swag.IsZero(m.ActiveFrom) { // not required
   115  		return nil
   116  	}
   117  
   118  	if err := validate.FormatOf("active_from", "body", "date-time", m.ActiveFrom.String(), formats); err != nil {
   119  		return err
   120  	}
   121  
   122  	return nil
   123  }
   124  
   125  func (m *Billing20201105ConsumptionPool) validateActiveUntil(formats strfmt.Registry) error {
   126  	if swag.IsZero(m.ActiveUntil) { // not required
   127  		return nil
   128  	}
   129  
   130  	if err := validate.FormatOf("active_until", "body", "date-time", m.ActiveUntil.String(), formats); err != nil {
   131  		return err
   132  	}
   133  
   134  	return nil
   135  }
   136  
   137  func (m *Billing20201105ConsumptionPool) validateCreatedAt(formats strfmt.Registry) error {
   138  	if swag.IsZero(m.CreatedAt) { // not required
   139  		return nil
   140  	}
   141  
   142  	if err := validate.FormatOf("created_at", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
   143  		return err
   144  	}
   145  
   146  	return nil
   147  }
   148  
   149  func (m *Billing20201105ConsumptionPool) validateDiscounts(formats strfmt.Registry) error {
   150  	if swag.IsZero(m.Discounts) { // not required
   151  		return nil
   152  	}
   153  
   154  	for i := 0; i < len(m.Discounts); i++ {
   155  		if swag.IsZero(m.Discounts[i]) { // not required
   156  			continue
   157  		}
   158  
   159  		if m.Discounts[i] != nil {
   160  			if err := m.Discounts[i].Validate(formats); err != nil {
   161  				if ve, ok := err.(*errors.Validation); ok {
   162  					return ve.ValidateName("discounts" + "." + strconv.Itoa(i))
   163  				} else if ce, ok := err.(*errors.CompositeError); ok {
   164  					return ce.ValidateName("discounts" + "." + strconv.Itoa(i))
   165  				}
   166  				return err
   167  			}
   168  		}
   169  
   170  	}
   171  
   172  	return nil
   173  }
   174  
   175  func (m *Billing20201105ConsumptionPool) validateStatus(formats strfmt.Registry) error {
   176  	if swag.IsZero(m.Status) { // not required
   177  		return nil
   178  	}
   179  
   180  	if m.Status != nil {
   181  		if err := m.Status.Validate(formats); err != nil {
   182  			if ve, ok := err.(*errors.Validation); ok {
   183  				return ve.ValidateName("status")
   184  			} else if ce, ok := err.(*errors.CompositeError); ok {
   185  				return ce.ValidateName("status")
   186  			}
   187  			return err
   188  		}
   189  	}
   190  
   191  	return nil
   192  }
   193  
   194  func (m *Billing20201105ConsumptionPool) validateSupportLevels(formats strfmt.Registry) error {
   195  	if swag.IsZero(m.SupportLevels) { // not required
   196  		return nil
   197  	}
   198  
   199  	for i := 0; i < len(m.SupportLevels); i++ {
   200  		if swag.IsZero(m.SupportLevels[i]) { // not required
   201  			continue
   202  		}
   203  
   204  		if m.SupportLevels[i] != nil {
   205  			if err := m.SupportLevels[i].Validate(formats); err != nil {
   206  				if ve, ok := err.(*errors.Validation); ok {
   207  					return ve.ValidateName("support_levels" + "." + strconv.Itoa(i))
   208  				} else if ce, ok := err.(*errors.CompositeError); ok {
   209  					return ce.ValidateName("support_levels" + "." + strconv.Itoa(i))
   210  				}
   211  				return err
   212  			}
   213  		}
   214  
   215  	}
   216  
   217  	return nil
   218  }
   219  
   220  func (m *Billing20201105ConsumptionPool) validateUpdatedAt(formats strfmt.Registry) error {
   221  	if swag.IsZero(m.UpdatedAt) { // not required
   222  		return nil
   223  	}
   224  
   225  	if err := validate.FormatOf("updated_at", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
   226  		return err
   227  	}
   228  
   229  	return nil
   230  }
   231  
   232  // ContextValidate validate this billing 20201105 consumption pool based on the context it is used
   233  func (m *Billing20201105ConsumptionPool) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   234  	var res []error
   235  
   236  	if err := m.contextValidateDiscounts(ctx, formats); err != nil {
   237  		res = append(res, err)
   238  	}
   239  
   240  	if err := m.contextValidateStatus(ctx, formats); err != nil {
   241  		res = append(res, err)
   242  	}
   243  
   244  	if err := m.contextValidateSupportLevels(ctx, formats); err != nil {
   245  		res = append(res, err)
   246  	}
   247  
   248  	if len(res) > 0 {
   249  		return errors.CompositeValidationError(res...)
   250  	}
   251  	return nil
   252  }
   253  
   254  func (m *Billing20201105ConsumptionPool) contextValidateDiscounts(ctx context.Context, formats strfmt.Registry) error {
   255  
   256  	for i := 0; i < len(m.Discounts); i++ {
   257  
   258  		if m.Discounts[i] != nil {
   259  			if err := m.Discounts[i].ContextValidate(ctx, formats); err != nil {
   260  				if ve, ok := err.(*errors.Validation); ok {
   261  					return ve.ValidateName("discounts" + "." + strconv.Itoa(i))
   262  				} else if ce, ok := err.(*errors.CompositeError); ok {
   263  					return ce.ValidateName("discounts" + "." + strconv.Itoa(i))
   264  				}
   265  				return err
   266  			}
   267  		}
   268  
   269  	}
   270  
   271  	return nil
   272  }
   273  
   274  func (m *Billing20201105ConsumptionPool) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {
   275  
   276  	if m.Status != nil {
   277  		if err := m.Status.ContextValidate(ctx, formats); err != nil {
   278  			if ve, ok := err.(*errors.Validation); ok {
   279  				return ve.ValidateName("status")
   280  			} else if ce, ok := err.(*errors.CompositeError); ok {
   281  				return ce.ValidateName("status")
   282  			}
   283  			return err
   284  		}
   285  	}
   286  
   287  	return nil
   288  }
   289  
   290  func (m *Billing20201105ConsumptionPool) contextValidateSupportLevels(ctx context.Context, formats strfmt.Registry) error {
   291  
   292  	for i := 0; i < len(m.SupportLevels); i++ {
   293  
   294  		if m.SupportLevels[i] != nil {
   295  			if err := m.SupportLevels[i].ContextValidate(ctx, formats); err != nil {
   296  				if ve, ok := err.(*errors.Validation); ok {
   297  					return ve.ValidateName("support_levels" + "." + strconv.Itoa(i))
   298  				} else if ce, ok := err.(*errors.CompositeError); ok {
   299  					return ce.ValidateName("support_levels" + "." + strconv.Itoa(i))
   300  				}
   301  				return err
   302  			}
   303  		}
   304  
   305  	}
   306  
   307  	return nil
   308  }
   309  
   310  // MarshalBinary interface implementation
   311  func (m *Billing20201105ConsumptionPool) MarshalBinary() ([]byte, error) {
   312  	if m == nil {
   313  		return nil, nil
   314  	}
   315  	return swag.WriteJSON(m)
   316  }
   317  
   318  // UnmarshalBinary interface implementation
   319  func (m *Billing20201105ConsumptionPool) UnmarshalBinary(b []byte) error {
   320  	var res Billing20201105ConsumptionPool
   321  	if err := swag.ReadJSON(b, &res); err != nil {
   322  		return err
   323  	}
   324  	*m = res
   325  	return nil
   326  }