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

// PreflightHardwareRequirements preflight hardware requirements
//
// swagger:model preflight-hardware-requirements
type PreflightHardwareRequirements struct {

	// Preflight OCP requirements
	Ocp *HostTypeHardwareRequirementsWrapper `json:"ocp,omitempty"`

	// Preflight operators hardware requirements
	Operators []*OperatorHardwareRequirements `json:"operators"`
}

// Validate validates this preflight hardware requirements
func (m *PreflightHardwareRequirements) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

	return nil
}

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

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

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

	}

	return nil
}

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

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

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

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

func (m *PreflightHardwareRequirements) contextValidateOcp(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *PreflightHardwareRequirements) contextValidateOperators(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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