github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_package_option.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  )
    16  
    17  // Billing20201105PackageOption PackageOption represents a selection of a PackageItem as part of a Package.
    18  //
    19  // swagger:model billing_20201105PackageOption
    20  type Billing20201105PackageOption struct {
    21  
    22  	// dependencies defines a dependency between this PackageOption and another
    23  	// Option a different item.
    24  	//
    25  	// Dependencies are optional, and when they are not set it means that the
    26  	// option could be used with any other combination of items/options.
    27  	//
    28  	// When they are set, all dependencies have to be met for this PackageOption to be active.
    29  	//
    30  	// Example scenario 1:
    31  	// - Item 1 has 2 Options: 1.1 and 1.2
    32  	// - Item 2 has also 2 Options: 2.1 and 2.2, and item 2 is of type SELECTION
    33  	// - Option 2.1 has a dependency on 1.1
    34  	// - Option 2.2 has a dependency on 1.2
    35  	// - If a user select 1.1, then 2.1 can be selected
    36  	// - If a user select 1.2, then 2.2 can be selected
    37  	//
    38  	// Example scenario 2:
    39  	// - Item 1 has 2 Options: 1.1 and 1.2
    40  	// - Item 2 has also 2 Options: 2.1 and 2.2, and item 2 is of type COST
    41  	// - Option 2.1 has a dependency on 1.1
    42  	// - Option 2.2 has a dependency on 1.2
    43  	// - If a user select 1.1, then 2.1 will be automatically be selected
    44  	// - If a user select 1.2, then 2.2 will be automatically be selected
    45  	//
    46  	//   In this scenario Item 1 could represent cluster size and Item 2 could
    47  	//   represent the mumber of clients. Selecting medium (1.2) affects the
    48  	//   price of the number of clients (2.2).
    49  	//
    50  	// Example scenario 3:
    51  	// - Item 1 has 2 Options: 1.1 and 1.2
    52  	// - Item 2 has also 2 Options: 2.1 and 2.2, and item 2 is of type SELECTION
    53  	// - Option 2.1 has no dependencies
    54  	// - Option 2.2 has no dependencies
    55  	// - Either options 2.1 and 2.2 can be selected by the user, regardless
    56  	//   of the item 1 option value.
    57  	Dependencies []*PackageOptionDependency `json:"dependencies"`
    58  
    59  	// key is the unique identifier of the Option for a given Item.
    60  	Key string `json:"key,omitempty"`
    61  
    62  	// unit is the type of measurement that is used to calculate the quantity used of this product.
    63  	Unit *Billing20201105Unit `json:"unit,omitempty"`
    64  
    65  	// unit_display_key contains an human label for the product unit.
    66  	// It will be present if the unit type is set to UNIT, as a way
    67  	// to clarify what the customer is going to be charged for.
    68  	UnitDisplayKey string `json:"unit_display_key,omitempty"`
    69  
    70  	// unit_price is the price of a single unit of the product in USD.
    71  	UnitPrice string `json:"unit_price,omitempty"`
    72  }
    73  
    74  // Validate validates this billing 20201105 package option
    75  func (m *Billing20201105PackageOption) Validate(formats strfmt.Registry) error {
    76  	var res []error
    77  
    78  	if err := m.validateDependencies(formats); err != nil {
    79  		res = append(res, err)
    80  	}
    81  
    82  	if err := m.validateUnit(formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if len(res) > 0 {
    87  		return errors.CompositeValidationError(res...)
    88  	}
    89  	return nil
    90  }
    91  
    92  func (m *Billing20201105PackageOption) validateDependencies(formats strfmt.Registry) error {
    93  	if swag.IsZero(m.Dependencies) { // not required
    94  		return nil
    95  	}
    96  
    97  	for i := 0; i < len(m.Dependencies); i++ {
    98  		if swag.IsZero(m.Dependencies[i]) { // not required
    99  			continue
   100  		}
   101  
   102  		if m.Dependencies[i] != nil {
   103  			if err := m.Dependencies[i].Validate(formats); err != nil {
   104  				if ve, ok := err.(*errors.Validation); ok {
   105  					return ve.ValidateName("dependencies" + "." + strconv.Itoa(i))
   106  				} else if ce, ok := err.(*errors.CompositeError); ok {
   107  					return ce.ValidateName("dependencies" + "." + strconv.Itoa(i))
   108  				}
   109  				return err
   110  			}
   111  		}
   112  
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  func (m *Billing20201105PackageOption) validateUnit(formats strfmt.Registry) error {
   119  	if swag.IsZero(m.Unit) { // not required
   120  		return nil
   121  	}
   122  
   123  	if m.Unit != nil {
   124  		if err := m.Unit.Validate(formats); err != nil {
   125  			if ve, ok := err.(*errors.Validation); ok {
   126  				return ve.ValidateName("unit")
   127  			} else if ce, ok := err.(*errors.CompositeError); ok {
   128  				return ce.ValidateName("unit")
   129  			}
   130  			return err
   131  		}
   132  	}
   133  
   134  	return nil
   135  }
   136  
   137  // ContextValidate validate this billing 20201105 package option based on the context it is used
   138  func (m *Billing20201105PackageOption) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   139  	var res []error
   140  
   141  	if err := m.contextValidateDependencies(ctx, formats); err != nil {
   142  		res = append(res, err)
   143  	}
   144  
   145  	if err := m.contextValidateUnit(ctx, formats); err != nil {
   146  		res = append(res, err)
   147  	}
   148  
   149  	if len(res) > 0 {
   150  		return errors.CompositeValidationError(res...)
   151  	}
   152  	return nil
   153  }
   154  
   155  func (m *Billing20201105PackageOption) contextValidateDependencies(ctx context.Context, formats strfmt.Registry) error {
   156  
   157  	for i := 0; i < len(m.Dependencies); i++ {
   158  
   159  		if m.Dependencies[i] != nil {
   160  			if err := m.Dependencies[i].ContextValidate(ctx, formats); err != nil {
   161  				if ve, ok := err.(*errors.Validation); ok {
   162  					return ve.ValidateName("dependencies" + "." + strconv.Itoa(i))
   163  				} else if ce, ok := err.(*errors.CompositeError); ok {
   164  					return ce.ValidateName("dependencies" + "." + strconv.Itoa(i))
   165  				}
   166  				return err
   167  			}
   168  		}
   169  
   170  	}
   171  
   172  	return nil
   173  }
   174  
   175  func (m *Billing20201105PackageOption) contextValidateUnit(ctx context.Context, formats strfmt.Registry) error {
   176  
   177  	if m.Unit != nil {
   178  		if err := m.Unit.ContextValidate(ctx, formats); err != nil {
   179  			if ve, ok := err.(*errors.Validation); ok {
   180  				return ve.ValidateName("unit")
   181  			} else if ce, ok := err.(*errors.CompositeError); ok {
   182  				return ce.ValidateName("unit")
   183  			}
   184  			return err
   185  		}
   186  	}
   187  
   188  	return nil
   189  }
   190  
   191  // MarshalBinary interface implementation
   192  func (m *Billing20201105PackageOption) MarshalBinary() ([]byte, error) {
   193  	if m == nil {
   194  		return nil, nil
   195  	}
   196  	return swag.WriteJSON(m)
   197  }
   198  
   199  // UnmarshalBinary interface implementation
   200  func (m *Billing20201105PackageOption) UnmarshalBinary(b []byte) error {
   201  	var res Billing20201105PackageOption
   202  	if err := swag.ReadJSON(b, &res); err != nil {
   203  		return err
   204  	}
   205  	*m = res
   206  	return nil
   207  }