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

// CloudconfigChangedParameter cloudconfig changed parameter
//
// swagger:model cloudconfig.ChangedParameter
type CloudconfigChangedParameter struct {

	// from
	From interface{} `json:"from,omitempty"`

	// from source
	FromSource CloudconfigParameterSource `json:"from_source,omitempty"`

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

	// to
	To interface{} `json:"to,omitempty"`

	// to source
	ToSource CloudconfigParameterSource `json:"to_source,omitempty"`
}

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

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

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

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

func (m *CloudconfigChangedParameter) validateFromSource(formats strfmt.Registry) error {
	if swag.IsZero(m.FromSource) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigChangedParameter) validateToSource(formats strfmt.Registry) error {
	if swag.IsZero(m.ToSource) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *CloudconfigChangedParameter) contextValidateFromSource(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *CloudconfigChangedParameter) contextValidateToSource(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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