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

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

// VersionedHostRequirements versioned host requirements
//
// swagger:model versioned-host-requirements
type VersionedHostRequirements struct {

	// Arbiter node requirements
	ArbiterRequirements *VersionedClusterHostRequirementsDetails `json:"arbiter,omitempty"`

	// Edge Worker OpenShift node requirements
	EdgeWorkerRequirements *VersionedClusterHostRequirementsDetails `json:"edge-worker,omitempty"`

	// Master node requirements
	MasterRequirements *VersionedClusterHostRequirementsDetails `json:"master,omitempty"`

	// Determines how the version field is matched. "exact" applies only to the specified version (default). "min_version" applies to the specified version and all later versions.
	// Enum: [exact min_version]
	MatchType string `json:"match_type,omitempty"`

	// Single node OpenShift node requirements
	SNORequirements *VersionedClusterHostRequirementsDetails `json:"sno,omitempty"`

	// Worker node requirements
	WorkerRequirements *VersionedClusterHostRequirementsDetails `json:"worker,omitempty"`

	// Version of the component for which requirements are defined
	Version string `json:"version,omitempty"`
}

// Validate validates this versioned host requirements
func (m *VersionedHostRequirements) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

	return nil
}

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

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

	return nil
}

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

	if m.MasterRequirements != nil {
		if err := m.MasterRequirements.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
}

var versionedHostRequirementsTypeMatchTypePropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["exact","min_version"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		versionedHostRequirementsTypeMatchTypePropEnum = append(versionedHostRequirementsTypeMatchTypePropEnum, v)
	}
}

const (

	// VersionedHostRequirementsMatchTypeExact captures enum value "exact"
	VersionedHostRequirementsMatchTypeExact string = "exact"

	// VersionedHostRequirementsMatchTypeMinVersion captures enum value "min_version"
	VersionedHostRequirementsMatchTypeMinVersion string = "min_version"
)

// prop value enum
func (m *VersionedHostRequirements) validateMatchTypeEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, versionedHostRequirementsTypeMatchTypePropEnum, true); err != nil {
		return err
	}
	return nil
}

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

	// value enum
	if err := m.validateMatchTypeEnum("match_type", "body", m.MatchType); err != nil {
		return err
	}

	return nil
}

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

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

	return nil
}

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

	if m.WorkerRequirements != nil {
		if err := m.WorkerRequirements.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 versioned host requirements based on the context it is used
func (m *VersionedHostRequirements) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *VersionedHostRequirements) contextValidateArbiterRequirements(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *VersionedHostRequirements) contextValidateEdgeWorkerRequirements(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *VersionedHostRequirements) contextValidateMasterRequirements(ctx context.Context, formats strfmt.Registry) error {

	if m.MasterRequirements != nil {
		if err := m.MasterRequirements.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 *VersionedHostRequirements) contextValidateSNORequirements(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *VersionedHostRequirements) contextValidateWorkerRequirements(ctx context.Context, formats strfmt.Registry) error {

	if m.WorkerRequirements != nil {
		if err := m.WorkerRequirements.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 *VersionedHostRequirements) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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