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

// SystemPoolCapacity Description of a System Pool's Capacity
//
// swagger:model SystemPoolCapacity
type SystemPoolCapacity struct {

	// Number of available cores in the System Pool
	// Required: true
	Cores *float64 `json:"cores"`

	// Amount of available memory in the System Pool (GB)
	// Required: true
	Memory *int64 `json:"memory"`

	// The DataCenter list of servers and their available resources
	Systems []*System `json:"systems"`

	// Total number of cores in the System Pool
	// Required: true
	TotalCores *float64 `json:"totalCores"`

	// Total amount of memory in the System Pool (GB)
	// Required: true
	TotalMemory *int64 `json:"totalMemory"`
}

// Validate validates this system pool capacity
func (m *SystemPoolCapacity) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *SystemPoolCapacity) validateCores(formats strfmt.Registry) error {

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

	return nil
}

func (m *SystemPoolCapacity) validateMemory(formats strfmt.Registry) error {

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

	return nil
}

func (m *SystemPoolCapacity) validateSystems(formats strfmt.Registry) error {
	if swag.IsZero(m.Systems) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *SystemPoolCapacity) validateTotalCores(formats strfmt.Registry) error {

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

	return nil
}

func (m *SystemPoolCapacity) validateTotalMemory(formats strfmt.Registry) error {

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

	return nil
}

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

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

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

func (m *SystemPoolCapacity) contextValidateSystems(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Systems[i] != nil {

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

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

	}

	return nil
}

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

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