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

// CloudconfigUnifiedParameter cloudconfig unified parameter
//
// swagger:model cloudconfig.UnifiedParameter
type CloudconfigUnifiedParameter struct {

	// attribute
	Attribute *CloudconfigUnifiedParameterAttribute `json:"attribute,omitempty"`

	// Comment is the comment of this parameter
	Comment string `json:"comment,omitempty"`

	// custom
	Custom *CloudconfigUnifiedParameterCustom `json:"custom,omitempty"`

	// Name is the name of this parameter
	Name string `json:"name,omitempty"`

	// source
	Source *CloudconfigUnifiedParameterSource `json:"source,omitempty"`

	// template
	Template *CloudconfigUnifiedParameterTemplate `json:"template,omitempty"`

	// Value is the value of this parameter
	Value interface{} `json:"value,omitempty"`
}

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

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

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

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

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

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

func (m *CloudconfigUnifiedParameter) validateAttribute(formats strfmt.Registry) error {
	if swag.IsZero(m.Attribute) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigUnifiedParameter) validateCustom(formats strfmt.Registry) error {
	if swag.IsZero(m.Custom) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigUnifiedParameter) validateSource(formats strfmt.Registry) error {
	if swag.IsZero(m.Source) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigUnifiedParameter) validateTemplate(formats strfmt.Registry) error {
	if swag.IsZero(m.Template) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

func (m *CloudconfigUnifiedParameter) contextValidateAttribute(ctx context.Context, formats strfmt.Registry) error {

	if m.Attribute != nil {

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

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

	return nil
}

func (m *CloudconfigUnifiedParameter) contextValidateCustom(ctx context.Context, formats strfmt.Registry) error {

	if m.Custom != nil {

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

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

	return nil
}

func (m *CloudconfigUnifiedParameter) contextValidateSource(ctx context.Context, formats strfmt.Registry) error {

	if m.Source != nil {

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

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

	return nil
}

func (m *CloudconfigUnifiedParameter) contextValidateTemplate(ctx context.Context, formats strfmt.Registry) error {

	if m.Template != nil {

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

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

	return nil
}

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

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