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

// OpenapiClusterConnectionStrings openapi cluster connection strings
//
// swagger:model openapiClusterConnectionStrings
type OpenapiClusterConnectionStrings struct {

	// The default TiDB user for connection.
	// Example: root
	DefaultUser string `json:"default_user,omitempty"`

	// standard
	Standard *OpenapiClusterConnectionStringsStandard `json:"standard,omitempty"`

	// vpc peering
	VpcPeering *OpenapiClusterConnectionStringsVpcPeering `json:"vpc_peering,omitempty"`
}

// Validate validates this openapi cluster connection strings
func (m *OpenapiClusterConnectionStrings) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *OpenapiClusterConnectionStrings) validateStandard(formats strfmt.Registry) error {
	if swag.IsZero(m.Standard) { // not required
		return nil
	}

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

	return nil
}

func (m *OpenapiClusterConnectionStrings) validateVpcPeering(formats strfmt.Registry) error {
	if swag.IsZero(m.VpcPeering) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *OpenapiClusterConnectionStrings) contextValidateStandard(ctx context.Context, formats strfmt.Registry) error {

	if m.Standard != nil {

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

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

	return nil
}

func (m *OpenapiClusterConnectionStrings) contextValidateVpcPeering(ctx context.Context, formats strfmt.Registry) error {

	if m.VpcPeering != nil {

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

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

	return nil
}

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

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

// OpenapiClusterConnectionStringsStandard Standard connection string.
//
// You must configure the [IP Access List](https://docs.pingcap.com/tidbcloud/connect-to-tidb-cluster#connect-via-standard-connection) for the cluster you created on [TiDB Cloud console](https://tidbcloud.com/) before connecting to this connection string.
//
// swagger:model OpenapiClusterConnectionStringsStandard
type OpenapiClusterConnectionStringsStandard struct {

	// The host of standard connection.
	// Example: tidb.f69f3808.acea1f2a.us-east-1.shared.aws.tidbcloud.com
	Host string `json:"host,omitempty"`

	// The TiDB port for connection. The port must be in the range of 1024-65535 except 10080.
	//
	// **Limitations**:
	// - For a TiDB Serverless cluster, only port `4000` is available.
	// Example: 4000
	// Maximum: 65535
	// Minimum: 1024
	Port int32 `json:"port,omitempty"`
}

// Validate validates this openapi cluster connection strings standard
func (m *OpenapiClusterConnectionStringsStandard) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

	return nil
}

// ContextValidate validates this openapi cluster connection strings standard based on context it is used
func (m *OpenapiClusterConnectionStringsStandard) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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

// OpenapiClusterConnectionStringsVpcPeering [VPC peering](https://docs.pingcap.com/tidbcloud/tidb-cloud-glossary#vpc-peering) connection string.
//
// You must [Set up VPC peering connections](https://docs.pingcap.com/tidbcloud/set-up-vpc-peering-connections) for the project before connecting to this private connection string.
//
// swagger:model OpenapiClusterConnectionStringsVpcPeering
type OpenapiClusterConnectionStringsVpcPeering struct {

	// The host of VPC peering connection.
	// Example: private-tidb.f69f3808.acea1f2a.us-east-1.shared.aws.tidbcloud.com
	Host string `json:"host,omitempty"`

	// The TiDB port for connection. The port must be in the range of 1024-65535 except 10080.
	//
	// **Limitations**:
	// - For a TiDB Serverless cluster, only port `4000` is available.
	// Example: 4000
	// Maximum: 65535
	// Minimum: 1024
	Port int32 `json:"port,omitempty"`
}

// Validate validates this openapi cluster connection strings vpc peering
func (m *OpenapiClusterConnectionStringsVpcPeering) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

	return nil
}

// ContextValidate validates this openapi cluster connection strings vpc peering based on context it is used
func (m *OpenapiClusterConnectionStringsVpcPeering) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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