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

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

// CloudconfigConfiguration cloudconfig configuration
//
// swagger:model cloudconfig.Configuration
type CloudconfigConfiguration struct {

	// key: component name
	Components map[string]CloudconfigComponent `json:"components,omitempty"`

	// key: filename
	Files map[string]CloudconfigFileConfiguration `json:"files,omitempty"`

	// target cluster
	TargetCluster *GithubComTidbcloudDevopsEntityCloudconfigClusterConfigurationLocator `json:"target_cluster,omitempty"`

	// target tenant
	TargetTenant *GithubComTidbcloudDevopsEntityCloudconfigTenantInitConfigurationLocator `json:"target_tenant,omitempty"`

	// version
	Version string `json:"version,omitempty"`
}

// Validate validates this cloudconfig configuration
func (m *CloudconfigConfiguration) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

	for k := range m.Components {

		if err := validate.Required("components"+"."+k, "body", m.Components[k]); err != nil {
			return err
		}
		if val, ok := m.Components[k]; ok {
			if err := val.Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("components" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("components" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

func (m *CloudconfigConfiguration) validateFiles(formats strfmt.Registry) error {
	if swag.IsZero(m.Files) { // not required
		return nil
	}

	for k := range m.Files {

		if err := validate.Required("files"+"."+k, "body", m.Files[k]); err != nil {
			return err
		}
		if val, ok := m.Files[k]; ok {
			if err := val.Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("files" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("files" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

func (m *CloudconfigConfiguration) validateTargetCluster(formats strfmt.Registry) error {
	if swag.IsZero(m.TargetCluster) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigConfiguration) validateTargetTenant(formats strfmt.Registry) error {
	if swag.IsZero(m.TargetTenant) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

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

	for k := range m.Components {

		if val, ok := m.Components[k]; ok {
			if err := val.ContextValidate(ctx, formats); err != nil {
				return err
			}
		}

	}

	return nil
}

func (m *CloudconfigConfiguration) contextValidateFiles(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.Files {

		if val, ok := m.Files[k]; ok {
			if err := val.ContextValidate(ctx, formats); err != nil {
				return err
			}
		}

	}

	return nil
}

func (m *CloudconfigConfiguration) contextValidateTargetCluster(ctx context.Context, formats strfmt.Registry) error {

	if m.TargetCluster != nil {

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

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

	return nil
}

func (m *CloudconfigConfiguration) contextValidateTargetTenant(ctx context.Context, formats strfmt.Registry) error {

	if m.TargetTenant != nil {

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

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

	return nil
}

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

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