// 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"
	"github.com/go-openapi/validate"
)

// CentralComponent central component
//
// swagger:model centralComponent
type CentralComponent struct {

	// node profile
	// Required: true
	NodeProfile *CentralNodeProfile `json:"node_profile"`

	// replicas
	// Required: true
	Replicas *int64 `json:"replicas"`
}

// Validate validates this central component
func (m *CentralComponent) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CentralComponent) validateNodeProfile(formats strfmt.Registry) error {

	if err := validate.Required("node_profile", "body", m.NodeProfile); err != nil {
		return err
	}

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

	return nil
}

func (m *CentralComponent) validateReplicas(formats strfmt.Registry) error {

	if err := validate.Required("replicas", "body", m.Replicas); err != nil {
		return err
	}

	return nil
}

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

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

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

func (m *CentralComponent) contextValidateNodeProfile(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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