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

package models

// 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"
)

// HashicorpCloudConsul20200826ClusterConfig ClusterConfig holds the configuration for a Consul cluster.
//
// swagger:model hashicorp.cloud.consul_20200826.ClusterConfig
type HashicorpCloudConsul20200826ClusterConfig struct {

	// capacity_config contains the configuration for the cluster size settings.
	CapacityConfig *HashicorpCloudConsul20200826CapacityConfig `json:"capacity_config,omitempty"`

	// consul_config allows altering certain fields relating to the Consul
	// cluster’s configuration.
	ConsulConfig *HashicorpCloudConsul20200826ConsulConfig `json:"consul_config,omitempty"`

	// maintenance_config contains the configuration for maintenance events such as
	// auto upgrades.
	MaintenanceConfig HashicorpCloudConsul20200826MaintenanceConfig `json:"maintenance_config,omitempty"`

	// NetworkConfig contains the network to launch the Consul cluster into.
	NetworkConfig *HashicorpCloudConsul20200826NetworkConfig `json:"network_config,omitempty"`

	// snapshot_config contains the configuration for how often to snapshot and
	// how many to maintain.
	SnapshotConfig HashicorpCloudConsul20200826SnapshotConfig `json:"snapshot_config,omitempty"`
}

// Validate validates this hashicorp cloud consul 20200826 cluster config
func (m *HashicorpCloudConsul20200826ClusterConfig) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *HashicorpCloudConsul20200826ClusterConfig) validateCapacityConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.CapacityConfig) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudConsul20200826ClusterConfig) validateConsulConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.ConsulConfig) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudConsul20200826ClusterConfig) validateNetworkConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.NetworkConfig) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud consul 20200826 cluster config based on the context it is used
func (m *HashicorpCloudConsul20200826ClusterConfig) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *HashicorpCloudConsul20200826ClusterConfig) contextValidateCapacityConfig(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *HashicorpCloudConsul20200826ClusterConfig) contextValidateConsulConfig(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *HashicorpCloudConsul20200826ClusterConfig) contextValidateNetworkConfig(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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