// 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"
	"github.com/go-openapi/validate"
)

// OpenapiGetClusterConfig openapi get cluster config
//
// swagger:model openapiGetClusterConfig
type OpenapiGetClusterConfig struct {

	// components
	Components *OpenapiGetClusterConfigComponents `json:"components,omitempty"`

	// The TiDB port for connection. The port must be in the range of 1024-65535 except 10080.
	// Example: 4000
	// Maximum: 65535
	// Minimum: 1024
	Port int32 `json:"port,omitempty"`
}

// Validate validates this openapi get cluster config
func (m *OpenapiGetClusterConfig) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *OpenapiGetClusterConfig) validateComponents(formats strfmt.Registry) error {
	if swag.IsZero(m.Components) { // not required
		return nil
	}

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

	return nil
}

func (m *OpenapiGetClusterConfig) validatePort(formats strfmt.Registry) error {
	if swag.IsZero(m.Port) { // not required
		return nil
	}

	if err := validate.MinimumInt("port", "body", int64(m.Port), 1024, false); err != nil {
		return err
	}

	if err := validate.MaximumInt("port", "body", int64(m.Port), 65535, false); err != nil {
		return err
	}

	return nil
}

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

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

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

func (m *OpenapiGetClusterConfig) contextValidateComponents(ctx context.Context, formats strfmt.Registry) error {

	if m.Components != nil {

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

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

	return nil
}

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

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

// OpenapiGetClusterConfigComponents The components of the cluster.
// Example: {"tidb":{"node_quantity":2,"node_size":"8C16G"},"tikv":{"node_quantity":3,"node_size":"8C32G","storage_size_gib":1024}}
//
// swagger:model OpenapiGetClusterConfigComponents
type OpenapiGetClusterConfigComponents struct {

	// tidb
	// Required: true
	Tidb *OpenapiGetClusterConfigComponentsTidb `json:"tidb"`

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

	// tikv
	// Required: true
	Tikv *OpenapiGetClusterConfigComponentsTikv `json:"tikv"`
}

// Validate validates this openapi get cluster config components
func (m *OpenapiGetClusterConfigComponents) 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 *OpenapiGetClusterConfigComponents) validateTidb(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tidb", "body", m.Tidb); err != nil {
		return err
	}

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

	return nil
}

func (m *OpenapiGetClusterConfigComponents) 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("components" + "." + "tiflash")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("components" + "." + "tiflash")
			}
			return err
		}
	}

	return nil
}

func (m *OpenapiGetClusterConfigComponents) validateTikv(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tikv", "body", m.Tikv); err != nil {
		return err
	}

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

	return nil
}

// ContextValidate validate this openapi get cluster config components based on the context it is used
func (m *OpenapiGetClusterConfigComponents) 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 *OpenapiGetClusterConfigComponents) contextValidateTidb(ctx context.Context, formats strfmt.Registry) error {

	if m.Tidb != nil {

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

	return nil
}

func (m *OpenapiGetClusterConfigComponents) 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("components" + "." + "tiflash")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("components" + "." + "tiflash")
			}
			return err
		}
	}

	return nil
}

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

	if m.Tikv != nil {

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

	return nil
}

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

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

// OpenapiGetClusterConfigComponentsTidb The TiDB component of the cluster.
//
// swagger:model OpenapiGetClusterConfigComponentsTidb
type OpenapiGetClusterConfigComponentsTidb 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
	// Required: true
	NodeQuantity *int32 `json:"node_quantity"`

	// 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.
	// Example: 8C16G
	// Required: true
	NodeSize *string `json:"node_size"`
}

// Validate validates this openapi get cluster config components tidb
func (m *OpenapiGetClusterConfigComponentsTidb) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *OpenapiGetClusterConfigComponentsTidb) validateNodeQuantity(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tidb"+"."+"node_quantity", "body", m.NodeQuantity); err != nil {
		return err
	}

	return nil
}

func (m *OpenapiGetClusterConfigComponentsTidb) validateNodeSize(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tidb"+"."+"node_size", "body", m.NodeSize); err != nil {
		return err
	}

	return nil
}

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

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

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

// OpenapiGetClusterConfigComponentsTiflash The TiFlash component of the cluster.
//
// swagger:model OpenapiGetClusterConfigComponentsTiflash
type OpenapiGetClusterConfigComponentsTiflash 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: 1
	// Required: true
	NodeQuantity *int32 `json:"node_quantity"`

	// 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.
	// Example: 8C64G
	// Required: true
	NodeSize *string `json:"node_size"`

	// 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).
	//
	// Example: 1024
	// Required: true
	StorageSizeGib *int32 `json:"storage_size_gib"`
}

// Validate validates this openapi get cluster config components tiflash
func (m *OpenapiGetClusterConfigComponentsTiflash) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *OpenapiGetClusterConfigComponentsTiflash) validateNodeQuantity(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tiflash"+"."+"node_quantity", "body", m.NodeQuantity); err != nil {
		return err
	}

	return nil
}

func (m *OpenapiGetClusterConfigComponentsTiflash) validateNodeSize(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tiflash"+"."+"node_size", "body", m.NodeSize); err != nil {
		return err
	}

	return nil
}

func (m *OpenapiGetClusterConfigComponentsTiflash) validateStorageSizeGib(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tiflash"+"."+"storage_size_gib", "body", m.StorageSizeGib); err != nil {
		return err
	}

	return nil
}

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

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

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

// OpenapiGetClusterConfigComponentsTikv The TiKV component of the cluster.
//
// swagger:model OpenapiGetClusterConfigComponentsTikv
type OpenapiGetClusterConfigComponentsTikv 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: 3
	// Required: true
	NodeQuantity *int32 `json:"node_quantity"`

	// 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.
	// Example: 8C64G
	// Required: true
	NodeSize *string `json:"node_size"`

	// 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).
	// Example: 1024
	// Required: true
	StorageSizeGib *int32 `json:"storage_size_gib"`
}

// Validate validates this openapi get cluster config components tikv
func (m *OpenapiGetClusterConfigComponentsTikv) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *OpenapiGetClusterConfigComponentsTikv) validateNodeQuantity(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tikv"+"."+"node_quantity", "body", m.NodeQuantity); err != nil {
		return err
	}

	return nil
}

func (m *OpenapiGetClusterConfigComponentsTikv) validateNodeSize(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tikv"+"."+"node_size", "body", m.NodeSize); err != nil {
		return err
	}

	return nil
}

func (m *OpenapiGetClusterConfigComponentsTikv) validateStorageSizeGib(formats strfmt.Registry) error {

	if err := validate.Required("components"+"."+"tikv"+"."+"storage_size_gib", "body", m.StorageSizeGib); err != nil {
		return err
	}

	return nil
}

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

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

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