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

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// CentralComponentNodeProfiles central component node profiles
//
// swagger:model centralComponentNodeProfiles
type CentralComponentNodeProfiles struct {

	// component type
	// Required: true
	ComponentType *CentralComponentType `json:"component_type"`

	// default profile id
	// Required: true
	DefaultProfileID *string `json:"default_profile_id"`

	// profiles
	// Required: true
	Profiles []*CentralClusterNodeProfile `json:"profiles"`
}

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

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

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

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

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

func (m *CentralComponentNodeProfiles) validateComponentType(formats strfmt.Registry) error {

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

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

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

	return nil
}

func (m *CentralComponentNodeProfiles) validateDefaultProfileID(formats strfmt.Registry) error {

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

	return nil
}

func (m *CentralComponentNodeProfiles) validateProfiles(formats strfmt.Registry) error {

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

	for i := 0; i < len(m.Profiles); i++ {
		if swag.IsZero(m.Profiles[i]) { // not required
			continue
		}

		if m.Profiles[i] != nil {
			if err := m.Profiles[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("profiles" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("profiles" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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

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

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

func (m *CentralComponentNodeProfiles) contextValidateComponentType(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *CentralComponentNodeProfiles) contextValidateProfiles(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Profiles); i++ {

		if m.Profiles[i] != nil {
			if err := m.Profiles[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("profiles" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("profiles" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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