// Code generated by go-swagger; DO NOT EDIT.

package ops

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"strconv"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// ClusterServerlessDetails cluster serverless details
//
// swagger:model cluster.ServerlessDetails
type ClusterServerlessDetails struct {

	// branches
	Branches []*ClusterServerlessBranch `json:"branches"`

	// column storage
	ColumnStorage float64 `json:"column_storage,omitempty"`

	// request unit
	RequestUnit int64 `json:"request_unit,omitempty"`

	// row storage
	RowStorage float64 `json:"row_storage,omitempty"`
}

// Validate validates this cluster serverless details
func (m *ClusterServerlessDetails) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateBranches(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *ClusterServerlessDetails) validateBranches(formats strfmt.Registry) error {
	if swag.IsZero(m.Branches) { // not required
		return nil
	}

	for i := 0; i < len(m.Branches); i++ {
		if swag.IsZero(m.Branches[i]) { // not required
			continue
		}

		if m.Branches[i] != nil {
			if err := m.Branches[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("branches" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("branches" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this cluster serverless details based on the context it is used
func (m *ClusterServerlessDetails) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateBranches(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *ClusterServerlessDetails) contextValidateBranches(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Branches); i++ {

		if m.Branches[i] != nil {

			if swag.IsZero(m.Branches[i]) { // not required
				return nil
			}

			if err := m.Branches[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("branches" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("branches" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// MarshalBinary interface implementation
func (m *ClusterServerlessDetails) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *ClusterServerlessDetails) UnmarshalBinary(b []byte) error {
	var res ClusterServerlessDetails
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
