// Code generated by go-swagger; DO NOT EDIT.

package models

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

// ControllerStepObject +kubebuilder:object:generate=true
// StepObject can represent any kubernetes object
//
// swagger:model controllerStepObject
type ControllerStepObject struct {

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

	// object meta
	ObjectMeta *V1ObjectMeta `json:"objectMeta,omitempty"`

	// raw
	// Format: byte
	Raw strfmt.Base64 `json:"raw,omitempty"`

	// type meta
	TypeMeta *Metav1TypeMeta `json:"typeMeta,omitempty"`
}

// Validate validates this controller step object
func (m *ControllerStepObject) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *ControllerStepObject) validateObjectMeta(formats strfmt.Registry) error {
	if swag.IsZero(m.ObjectMeta) { // not required
		return nil
	}

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

	return nil
}

func (m *ControllerStepObject) validateTypeMeta(formats strfmt.Registry) error {
	if swag.IsZero(m.TypeMeta) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this controller step object based on the context it is used
func (m *ControllerStepObject) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *ControllerStepObject) contextValidateObjectMeta(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *ControllerStepObject) contextValidateTypeMeta(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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