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

// SharedProcessorPoolDetail shared processor pool detail
//
// swagger:model SharedProcessorPoolDetail
type SharedProcessorPoolDetail struct {

	// list of servers deployed in the Shared Processor Pool
	// Required: true
	Servers []*SharedProcessorPoolServer `json:"servers"`

	// shared processor pool
	// Required: true
	SharedProcessorPool *SharedProcessorPool `json:"sharedProcessorPool"`
}

// Validate validates this shared processor pool detail
func (m *SharedProcessorPoolDetail) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SharedProcessorPoolDetail) validateServers(formats strfmt.Registry) error {

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

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

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

	}

	return nil
}

func (m *SharedProcessorPoolDetail) validateSharedProcessorPool(formats strfmt.Registry) error {

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

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

	return nil
}

// ContextValidate validate this shared processor pool detail based on the context it is used
func (m *SharedProcessorPoolDetail) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SharedProcessorPoolDetail) contextValidateServers(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Servers[i] != nil {

			if swag.IsZero(m.Servers[i]) { // not required
				return nil
			}

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

	}

	return nil
}

func (m *SharedProcessorPoolDetail) contextValidateSharedProcessorPool(ctx context.Context, formats strfmt.Registry) error {

	if m.SharedProcessorPool != nil {

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

	return nil
}

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

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