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

// StorageTypesCapacity Storage types capacity
//
// swagger:model StorageTypesCapacity
type StorageTypesCapacity struct {

	// maximum storage allocation
	MaximumStorageAllocation *MaximumStorageAllocation `json:"maximumStorageAllocation,omitempty"`

	// storage types capacity
	StorageTypesCapacity []*StorageTypeCapacity `json:"storageTypesCapacity"`
}

// Validate validates this storage types capacity
func (m *StorageTypesCapacity) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *StorageTypesCapacity) validateMaximumStorageAllocation(formats strfmt.Registry) error {
	if swag.IsZero(m.MaximumStorageAllocation) { // not required
		return nil
	}

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

	return nil
}

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

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

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

	}

	return nil
}

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

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

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

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

func (m *StorageTypesCapacity) contextValidateMaximumStorageAllocation(ctx context.Context, formats strfmt.Registry) error {

	if m.MaximumStorageAllocation != nil {

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

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

	return nil
}

func (m *StorageTypesCapacity) contextValidateStorageTypesCapacity(ctx context.Context, formats strfmt.Registry) error {

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

		if m.StorageTypesCapacity[i] != nil {

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

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

	}

	return nil
}

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

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