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

// CloudconfigParameterAttribute cloudconfig parameter attribute
//
// swagger:model cloudconfig.ParameterAttribute
type CloudconfigParameterAttribute struct {

	// apply policy
	ApplyPolicy CloudconfigParameterApplyPolicy `json:"apply_policy,omitempty"`

	// config type
	ConfigType string `json:"config_type,omitempty"`

	// default value
	DefaultValue interface{} `json:"default_value,omitempty"`

	// description
	Description string `json:"description,omitempty"`

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

	// type
	Type string `json:"type,omitempty"`

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

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

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

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

func (m *CloudconfigParameterAttribute) validateApplyPolicy(formats strfmt.Registry) error {
	if swag.IsZero(m.ApplyPolicy) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *CloudconfigParameterAttribute) contextValidateApplyPolicy(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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