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

// Copyright Authors of Cilium
// SPDX-License-Identifier: Apache-2.0

package models

import (
	"context"
	stderrors "errors"

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

// EndpointStatus The current state and configuration of the endpoint, its policy & datapath, and subcomponents
//
// swagger:model EndpointStatus
type EndpointStatus struct {

	// Status of internal controllers attached to this endpoint
	Controllers ControllerStatuses `json:"controllers,omitempty"`

	// Unique identifiers for this endpoint from outside cilium
	ExternalIdentifiers *EndpointIdentifiers `json:"external-identifiers,omitempty"`

	// Summary overall endpoint & subcomponent health
	Health *EndpointHealth `json:"health,omitempty"`

	// The security identity for this endpoint
	Identity *Identity `json:"identity,omitempty"`

	// Labels applied to this endpoint
	Labels *LabelConfigurationStatus `json:"labels,omitempty"`

	// Most recent status log. See endpoint/{id}/log for the complete log.
	Log EndpointStatusLog `json:"log,omitempty"`

	// List of named ports that can be used in Network Policy
	NamedPorts NamedPorts `json:"namedPorts,omitempty"`

	// Networking properties of the endpoint
	Networking *EndpointNetworking `json:"networking,omitempty"`

	// The policy applied to this endpoint from the policy repository
	Policy *EndpointPolicyStatus `json:"policy,omitempty"`

	// The configuration in effect on this endpoint
	Realized *EndpointConfigurationSpec `json:"realized,omitempty"`

	// Current state of endpoint
	// Required: true
	State *EndpointState `json:"state"`
}

// Validate validates this endpoint status
func (m *EndpointStatus) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

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

func (m *EndpointStatus) validateControllers(formats strfmt.Registry) error {
	if swag.IsZero(m.Controllers) { // not required
		return nil
	}

	if err := m.Controllers.Validate(formats); err != nil {
		ve := new(errors.Validation)
		if stderrors.As(err, &ve) {
			return ve.ValidateName("controllers")
		}
		ce := new(errors.CompositeError)
		if stderrors.As(err, &ce) {
			return ce.ValidateName("controllers")
		}

		return err
	}

	return nil
}

func (m *EndpointStatus) validateExternalIdentifiers(formats strfmt.Registry) error {
	if swag.IsZero(m.ExternalIdentifiers) { // not required
		return nil
	}

	if m.ExternalIdentifiers != nil {
		if err := m.ExternalIdentifiers.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("external-identifiers")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("external-identifiers")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validateHealth(formats strfmt.Registry) error {
	if swag.IsZero(m.Health) { // not required
		return nil
	}

	if m.Health != nil {
		if err := m.Health.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("health")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("health")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validateIdentity(formats strfmt.Registry) error {
	if swag.IsZero(m.Identity) { // not required
		return nil
	}

	if m.Identity != nil {
		if err := m.Identity.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("identity")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("identity")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validateLabels(formats strfmt.Registry) error {
	if swag.IsZero(m.Labels) { // not required
		return nil
	}

	if m.Labels != nil {
		if err := m.Labels.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("labels")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("labels")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validateLog(formats strfmt.Registry) error {
	if swag.IsZero(m.Log) { // not required
		return nil
	}

	if err := m.Log.Validate(formats); err != nil {
		ve := new(errors.Validation)
		if stderrors.As(err, &ve) {
			return ve.ValidateName("log")
		}
		ce := new(errors.CompositeError)
		if stderrors.As(err, &ce) {
			return ce.ValidateName("log")
		}

		return err
	}

	return nil
}

func (m *EndpointStatus) validateNamedPorts(formats strfmt.Registry) error {
	if swag.IsZero(m.NamedPorts) { // not required
		return nil
	}

	if err := m.NamedPorts.Validate(formats); err != nil {
		ve := new(errors.Validation)
		if stderrors.As(err, &ve) {
			return ve.ValidateName("namedPorts")
		}
		ce := new(errors.CompositeError)
		if stderrors.As(err, &ce) {
			return ce.ValidateName("namedPorts")
		}

		return err
	}

	return nil
}

func (m *EndpointStatus) validateNetworking(formats strfmt.Registry) error {
	if swag.IsZero(m.Networking) { // not required
		return nil
	}

	if m.Networking != nil {
		if err := m.Networking.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("networking")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("networking")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validatePolicy(formats strfmt.Registry) error {
	if swag.IsZero(m.Policy) { // not required
		return nil
	}

	if m.Policy != nil {
		if err := m.Policy.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("policy")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("policy")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validateRealized(formats strfmt.Registry) error {
	if swag.IsZero(m.Realized) { // not required
		return nil
	}

	if m.Realized != nil {
		if err := m.Realized.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("realized")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("realized")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) validateState(formats strfmt.Registry) error {

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

	if m.State != nil {
		if err := m.State.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("state")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("state")
			}

			return err
		}
	}

	return nil
}

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

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

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

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

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

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

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

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

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

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

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

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

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

func (m *EndpointStatus) contextValidateControllers(ctx context.Context, formats strfmt.Registry) error {

	if err := m.Controllers.ContextValidate(ctx, formats); err != nil {
		ve := new(errors.Validation)
		if stderrors.As(err, &ve) {
			return ve.ValidateName("controllers")
		}
		ce := new(errors.CompositeError)
		if stderrors.As(err, &ce) {
			return ce.ValidateName("controllers")
		}

		return err
	}

	return nil
}

func (m *EndpointStatus) contextValidateExternalIdentifiers(ctx context.Context, formats strfmt.Registry) error {

	if m.ExternalIdentifiers != nil {

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

		if err := m.ExternalIdentifiers.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("external-identifiers")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("external-identifiers")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidateHealth(ctx context.Context, formats strfmt.Registry) error {

	if m.Health != nil {

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

		if err := m.Health.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("health")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("health")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidateIdentity(ctx context.Context, formats strfmt.Registry) error {

	if m.Identity != nil {

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

		if err := m.Identity.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("identity")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("identity")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {

	if m.Labels != nil {

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

		if err := m.Labels.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("labels")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("labels")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidateLog(ctx context.Context, formats strfmt.Registry) error {

	if err := m.Log.ContextValidate(ctx, formats); err != nil {
		ve := new(errors.Validation)
		if stderrors.As(err, &ve) {
			return ve.ValidateName("log")
		}
		ce := new(errors.CompositeError)
		if stderrors.As(err, &ce) {
			return ce.ValidateName("log")
		}

		return err
	}

	return nil
}

func (m *EndpointStatus) contextValidateNamedPorts(ctx context.Context, formats strfmt.Registry) error {

	if err := m.NamedPorts.ContextValidate(ctx, formats); err != nil {
		ve := new(errors.Validation)
		if stderrors.As(err, &ve) {
			return ve.ValidateName("namedPorts")
		}
		ce := new(errors.CompositeError)
		if stderrors.As(err, &ce) {
			return ce.ValidateName("namedPorts")
		}

		return err
	}

	return nil
}

func (m *EndpointStatus) contextValidateNetworking(ctx context.Context, formats strfmt.Registry) error {

	if m.Networking != nil {

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

		if err := m.Networking.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("networking")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("networking")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidatePolicy(ctx context.Context, formats strfmt.Registry) error {

	if m.Policy != nil {

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

		if err := m.Policy.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("policy")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("policy")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidateRealized(ctx context.Context, formats strfmt.Registry) error {

	if m.Realized != nil {

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

		if err := m.Realized.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("realized")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("realized")
			}

			return err
		}
	}

	return nil
}

func (m *EndpointStatus) contextValidateState(ctx context.Context, formats strfmt.Registry) error {

	if m.State != nil {

		if err := m.State.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("state")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("state")
			}

			return err
		}
	}

	return nil
}

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

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