github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-billing/preview/2020-11-05/models/billing20201105_billing_account.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  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/go-openapi/swag"
    14  )
    15  
    16  // Billing20201105BillingAccount BillingAccount is the user-facing object in HCP that defines how an
    17  // organization will be billed for the resources used in their projects.
    18  //
    19  // swagger:model billing_20201105BillingAccount
    20  type Billing20201105BillingAccount struct {
    21  
    22  	// balance is the account's current credit balance. Credit is added to an
    23  	// account's balance for example when it is eligible for a free trial.
    24  	Balance string `json:"balance,omitempty"`
    25  
    26  	// country is the billing account's country that is used both in the billing
    27  	// address and for selecting regional prices.
    28  	Country *Billing20201105Country `json:"country,omitempty"`
    29  
    30  	// id is the user-settable ID for this Billing Account. It is unique within
    31  	// the organization.
    32  	ID string `json:"id,omitempty"`
    33  
    34  	// name is the Billing Account's user-defined name.
    35  	Name string `json:"name,omitempty"`
    36  
    37  	// on_demand_status represents the status of the on-demand payment method.
    38  	OnDemandStatus *BillingAccountOnDemandStatus `json:"on_demand_status,omitempty"`
    39  
    40  	// organization_id is the ID of the organization to which the Billing Account
    41  	// belongs.
    42  	OrganizationID string `json:"organization_id,omitempty"`
    43  
    44  	// project_ids is the list of IDs of all projects associated with the Billing
    45  	// Account. Projects can be linked to *at most* one Billing Account.
    46  	ProjectIds []string `json:"project_ids"`
    47  
    48  	// status of the billing account (e.g. active, canceled).
    49  	Status *Billing20201105BillingAccountStatus `json:"status,omitempty"`
    50  }
    51  
    52  // Validate validates this billing 20201105 billing account
    53  func (m *Billing20201105BillingAccount) Validate(formats strfmt.Registry) error {
    54  	var res []error
    55  
    56  	if err := m.validateCountry(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if err := m.validateOnDemandStatus(formats); err != nil {
    61  		res = append(res, err)
    62  	}
    63  
    64  	if err := m.validateStatus(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 *Billing20201105BillingAccount) validateCountry(formats strfmt.Registry) error {
    75  	if swag.IsZero(m.Country) { // not required
    76  		return nil
    77  	}
    78  
    79  	if m.Country != nil {
    80  		if err := m.Country.Validate(formats); err != nil {
    81  			if ve, ok := err.(*errors.Validation); ok {
    82  				return ve.ValidateName("country")
    83  			} else if ce, ok := err.(*errors.CompositeError); ok {
    84  				return ce.ValidateName("country")
    85  			}
    86  			return err
    87  		}
    88  	}
    89  
    90  	return nil
    91  }
    92  
    93  func (m *Billing20201105BillingAccount) validateOnDemandStatus(formats strfmt.Registry) error {
    94  	if swag.IsZero(m.OnDemandStatus) { // not required
    95  		return nil
    96  	}
    97  
    98  	if m.OnDemandStatus != nil {
    99  		if err := m.OnDemandStatus.Validate(formats); err != nil {
   100  			if ve, ok := err.(*errors.Validation); ok {
   101  				return ve.ValidateName("on_demand_status")
   102  			} else if ce, ok := err.(*errors.CompositeError); ok {
   103  				return ce.ValidateName("on_demand_status")
   104  			}
   105  			return err
   106  		}
   107  	}
   108  
   109  	return nil
   110  }
   111  
   112  func (m *Billing20201105BillingAccount) validateStatus(formats strfmt.Registry) error {
   113  	if swag.IsZero(m.Status) { // not required
   114  		return nil
   115  	}
   116  
   117  	if m.Status != nil {
   118  		if err := m.Status.Validate(formats); err != nil {
   119  			if ve, ok := err.(*errors.Validation); ok {
   120  				return ve.ValidateName("status")
   121  			} else if ce, ok := err.(*errors.CompositeError); ok {
   122  				return ce.ValidateName("status")
   123  			}
   124  			return err
   125  		}
   126  	}
   127  
   128  	return nil
   129  }
   130  
   131  // ContextValidate validate this billing 20201105 billing account based on the context it is used
   132  func (m *Billing20201105BillingAccount) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   133  	var res []error
   134  
   135  	if err := m.contextValidateCountry(ctx, formats); err != nil {
   136  		res = append(res, err)
   137  	}
   138  
   139  	if err := m.contextValidateOnDemandStatus(ctx, formats); err != nil {
   140  		res = append(res, err)
   141  	}
   142  
   143  	if err := m.contextValidateStatus(ctx, formats); err != nil {
   144  		res = append(res, err)
   145  	}
   146  
   147  	if len(res) > 0 {
   148  		return errors.CompositeValidationError(res...)
   149  	}
   150  	return nil
   151  }
   152  
   153  func (m *Billing20201105BillingAccount) contextValidateCountry(ctx context.Context, formats strfmt.Registry) error {
   154  
   155  	if m.Country != nil {
   156  		if err := m.Country.ContextValidate(ctx, formats); err != nil {
   157  			if ve, ok := err.(*errors.Validation); ok {
   158  				return ve.ValidateName("country")
   159  			} else if ce, ok := err.(*errors.CompositeError); ok {
   160  				return ce.ValidateName("country")
   161  			}
   162  			return err
   163  		}
   164  	}
   165  
   166  	return nil
   167  }
   168  
   169  func (m *Billing20201105BillingAccount) contextValidateOnDemandStatus(ctx context.Context, formats strfmt.Registry) error {
   170  
   171  	if m.OnDemandStatus != nil {
   172  		if err := m.OnDemandStatus.ContextValidate(ctx, formats); err != nil {
   173  			if ve, ok := err.(*errors.Validation); ok {
   174  				return ve.ValidateName("on_demand_status")
   175  			} else if ce, ok := err.(*errors.CompositeError); ok {
   176  				return ce.ValidateName("on_demand_status")
   177  			}
   178  			return err
   179  		}
   180  	}
   181  
   182  	return nil
   183  }
   184  
   185  func (m *Billing20201105BillingAccount) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {
   186  
   187  	if m.Status != nil {
   188  		if err := m.Status.ContextValidate(ctx, formats); err != nil {
   189  			if ve, ok := err.(*errors.Validation); ok {
   190  				return ve.ValidateName("status")
   191  			} else if ce, ok := err.(*errors.CompositeError); ok {
   192  				return ce.ValidateName("status")
   193  			}
   194  			return err
   195  		}
   196  	}
   197  
   198  	return nil
   199  }
   200  
   201  // MarshalBinary interface implementation
   202  func (m *Billing20201105BillingAccount) MarshalBinary() ([]byte, error) {
   203  	if m == nil {
   204  		return nil, nil
   205  	}
   206  	return swag.WriteJSON(m)
   207  }
   208  
   209  // UnmarshalBinary interface implementation
   210  func (m *Billing20201105BillingAccount) UnmarshalBinary(b []byte) error {
   211  	var res Billing20201105BillingAccount
   212  	if err := swag.ReadJSON(b, &res); err != nil {
   213  		return err
   214  	}
   215  	*m = res
   216  	return nil
   217  }