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

// CloudconfigPreviewConfigurationChangeResp cloudconfig preview configuration change resp
//
// swagger:model cloudconfig.PreviewConfigurationChangeResp
type CloudconfigPreviewConfigurationChangeResp struct {

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

	// change
	Change *GithubComTidbcloudDevopsEntityCloudconfigConfigurationChange `json:"change,omitempty"`

	// configuration
	Configuration *CloudconfigConfiguration `json:"configuration,omitempty"`

	// errcode
	Errcode APIErrCode `json:"errcode,omitempty"`

	// errmsg
	Errmsg string `json:"errmsg,omitempty"`

	// reasons
	Reasons string `json:"reasons,omitempty"`

	// trace id
	TraceID string `json:"trace_id,omitempty"`
}

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

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

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

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

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

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

func (m *CloudconfigPreviewConfigurationChangeResp) 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
}

func (m *CloudconfigPreviewConfigurationChangeResp) validateChange(formats strfmt.Registry) error {
	if swag.IsZero(m.Change) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigPreviewConfigurationChangeResp) validateConfiguration(formats strfmt.Registry) error {
	if swag.IsZero(m.Configuration) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudconfigPreviewConfigurationChangeResp) validateErrcode(formats strfmt.Registry) error {
	if swag.IsZero(m.Errcode) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

func (m *CloudconfigPreviewConfigurationChangeResp) 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
}

func (m *CloudconfigPreviewConfigurationChangeResp) contextValidateChange(ctx context.Context, formats strfmt.Registry) error {

	if m.Change != nil {

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

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

	return nil
}

func (m *CloudconfigPreviewConfigurationChangeResp) contextValidateConfiguration(ctx context.Context, formats strfmt.Registry) error {

	if m.Configuration != nil {

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

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

	return nil
}

func (m *CloudconfigPreviewConfigurationChangeResp) contextValidateErrcode(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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