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

// CloudconfigConfigurationTemplate cloudconfig configuration template
//
// swagger:model cloudconfig.ConfigurationTemplate
type CloudconfigConfigurationTemplate struct {

	// cluster type
	ClusterType CloudconfigClusterType `json:"cluster_type,omitempty"`

	// filename
	Filename string `json:"filename,omitempty"`

	// id in the config center
	ID int64 `json:"id,omitempty"`

	// name
	Name string `json:"name,omitempty"`

	// key: parameter name
	Parameters map[string]CloudconfigNamedParameter `json:"parameters,omitempty"`
}

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

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

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

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

func (m *CloudconfigConfigurationTemplate) validateClusterType(formats strfmt.Registry) error {
	if swag.IsZero(m.ClusterType) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigConfigurationTemplate) validateParameters(formats strfmt.Registry) error {
	if swag.IsZero(m.Parameters) { // not required
		return nil
	}

	for k := range m.Parameters {

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

	}

	return nil
}

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

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

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

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

func (m *CloudconfigConfigurationTemplate) contextValidateClusterType(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *CloudconfigConfigurationTemplate) contextValidateParameters(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.Parameters {

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

	}

	return nil
}

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

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