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

package model

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

import (
	"context"

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

// OpenapiUpdateClusterComponents openapi update cluster components
//
// swagger:model openapiUpdateClusterComponents
type OpenapiUpdateClusterComponents struct {

	// tidb
	Tidb *OpenapiUpdateClusterComponentsTidb `json:"tidb,omitempty"`

	// tiflash
	Tiflash *OpenapiUpdateClusterComponentsTiflash `json:"tiflash,omitempty"`

	// tikv
	Tikv *OpenapiUpdateClusterComponentsTikv `json:"tikv,omitempty"`
}

// Validate validates this openapi update cluster components
func (m *OpenapiUpdateClusterComponents) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *OpenapiUpdateClusterComponents) validateTidb(formats strfmt.Registry) error {
	if swag.IsZero(m.Tidb) { // not required
		return nil
	}

	if m.Tidb != nil {
		if err := m.Tidb.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("tidb")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("tidb")
			}
			return err
		}
	}

	return nil
}

func (m *OpenapiUpdateClusterComponents) validateTiflash(formats strfmt.Registry) error {
	if swag.IsZero(m.Tiflash) { // not required
		return nil
	}

	if m.Tiflash != nil {
		if err := m.Tiflash.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("tiflash")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("tiflash")
			}
			return err
		}
	}

	return nil
}

func (m *OpenapiUpdateClusterComponents) validateTikv(formats strfmt.Registry) error {
	if swag.IsZero(m.Tikv) { // not required
		return nil
	}

	if m.Tikv != nil {
		if err := m.Tikv.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("tikv")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("tikv")
			}
			return err
		}
	}

	return nil
}

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

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

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

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

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

func (m *OpenapiUpdateClusterComponents) contextValidateTidb(ctx context.Context, formats strfmt.Registry) error {

	if m.Tidb != nil {

		if swag.IsZero(m.Tidb) { // not required
			return nil
		}

		if err := m.Tidb.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("tidb")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("tidb")
			}
			return err
		}
	}

	return nil
}

func (m *OpenapiUpdateClusterComponents) contextValidateTiflash(ctx context.Context, formats strfmt.Registry) error {

	if m.Tiflash != nil {

		if swag.IsZero(m.Tiflash) { // not required
			return nil
		}

		if err := m.Tiflash.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("tiflash")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("tiflash")
			}
			return err
		}
	}

	return nil
}

func (m *OpenapiUpdateClusterComponents) contextValidateTikv(ctx context.Context, formats strfmt.Registry) error {

	if m.Tikv != nil {

		if swag.IsZero(m.Tikv) { // not required
			return nil
		}

		if err := m.Tikv.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("tikv")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("tikv")
			}
			return err
		}
	}

	return nil
}

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

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

// OpenapiUpdateClusterComponentsTidb The TiDB component of the cluster.
//
// swagger:model OpenapiUpdateClusterComponentsTidb
type OpenapiUpdateClusterComponentsTidb struct {

	// The ID of the accesspoint.
	// Example: 1
	AccesspointID string `json:"accesspoint_id,omitempty"`

	// The number of nodes in the cluster. You can get the minimum and step of a node quantity from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	// Example: 3
	NodeQuantity int32 `json:"node_quantity,omitempty"`

	// The size of the TiDB component in the cluster. You can get the available node size of each region from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	//
	// **Additional combination rules**:
	// - If the vCPUs of TiDB or TiKV component is 4, then their vCPUs need to be the same.
	// - If the vCPUs of TiDB or TiKV component is 4, then the cluster does not support TiFlash.
	//
	// **Limitations**:
	// - See [Change node size](https://docs.pingcap.com/tidbcloud/scale-tidb-cluster#change-node-size).
	// Example: 16C32G
	NodeSize string `json:"node_size,omitempty"`
}

// Validate validates this openapi update cluster components tidb
func (m *OpenapiUpdateClusterComponentsTidb) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this openapi update cluster components tidb based on context it is used
func (m *OpenapiUpdateClusterComponentsTidb) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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

// OpenapiUpdateClusterComponentsTiflash The TiFlash component of the cluster.
//
// If you want to add TiFlash nodes to a cluster that does not have one before (increase the node_quantity of `"TIFLASH"` from 0), you must specify the `node_size`, `storage_size_gib` and `node_quantity` of TiFlash nodes.
//
// swagger:model OpenapiUpdateClusterComponentsTiflash
type OpenapiUpdateClusterComponentsTiflash struct {

	// The number of nodes in the cluster. You can get the minimum and step of a node quantity from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	// Example: 2
	NodeQuantity int32 `json:"node_quantity,omitempty"`

	// The size of the TiFlash component in the cluster. You can get the available node size of each region from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	//
	// **Additional combination rules**:
	// - If the vCPUs of TiDB or TiKV component is 4, then their vCPUs need to be the same.
	// - If the vCPUs of TiDB or TiKV component is 4, then the cluster does not support TiFlash.
	//
	// **Limitations**:
	// - See [Change node size](https://docs.pingcap.com/tidbcloud/scale-tidb-cluster#change-node-size).
	// Example: 16C128G
	NodeSize string `json:"node_size,omitempty"`

	// The storage size of a node in the cluster. You can get the minimum and maximum of storage size from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	//
	// **Limitations**:
	// - You cannot decrease storage size for TiFlash.
	// - If your TiDB cluster is hosted by AWS, after changing the storage size of TiFlash, you must wait at least six hours before you can change it again.
	// Example: 2048
	StorageSizeGib int32 `json:"storage_size_gib,omitempty"`
}

// Validate validates this openapi update cluster components tiflash
func (m *OpenapiUpdateClusterComponentsTiflash) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this openapi update cluster components tiflash based on context it is used
func (m *OpenapiUpdateClusterComponentsTiflash) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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

// OpenapiUpdateClusterComponentsTikv The TiKV component of the cluster.
//
// swagger:model OpenapiUpdateClusterComponentsTikv
type OpenapiUpdateClusterComponentsTikv struct {

	// The number of nodes in the cluster. You can get the minimum and step of a node quantity from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	//
	// **Limitations**:
	// - The `node_quantity` of TiKV must be a multiple of 3.
	// Example: 6
	NodeQuantity int32 `json:"node_quantity,omitempty"`

	// The size of the TiKV component in the cluster. You can get the available node size of each region from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	//
	// **Additional combination rules**:
	// - If the vCPUs of TiDB or TiKV component is 4, then their vCPUs need to be the same.
	// - If the vCPUs of TiDB or TiKV component is 4, then the cluster does not support TiFlash.
	//
	// **Limitations**:
	// - See [Change node size](https://docs.pingcap.com/tidbcloud/scale-tidb-cluster#change-node-size).
	// Example: 16C64G
	NodeSize string `json:"node_size,omitempty"`

	// The storage size of a node in the cluster. You can get the minimum and maximum of storage size from the response of [List the cloud providers, regions and available specifications](#tag/Cluster/operation/ListProviderRegions).
	//
	// **Limitations**:
	// - You cannot decrease storage size for TiKV.
	// - If your TiDB cluster is hosted by AWS, after changing the storage size of TiKV, you must wait at least six hours before you can change it again.
	// Example: 2048
	StorageSizeGib int32 `json:"storage_size_gib,omitempty"`
}

// Validate validates this openapi update cluster components tikv
func (m *OpenapiUpdateClusterComponentsTikv) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this openapi update cluster components tikv based on context it is used
func (m *OpenapiUpdateClusterComponentsTikv) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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