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

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

// HostTypeHardwareRequirementsWrapper host type hardware requirements wrapper
//
// swagger:model host-type-hardware-requirements-wrapper
type HostTypeHardwareRequirementsWrapper struct {

	// Requirements towards a master node
	Master *HostTypeHardwareRequirements `json:"master,omitempty"`

	// Requirements towards a worker node
	Worker *HostTypeHardwareRequirements `json:"worker,omitempty"`
}

// Validate validates this host type hardware requirements wrapper
func (m *HostTypeHardwareRequirementsWrapper) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

	return nil
}

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

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

	return nil
}

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

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

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

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

func (m *HostTypeHardwareRequirementsWrapper) contextValidateMaster(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *HostTypeHardwareRequirementsWrapper) contextValidateWorker(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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