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

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

// HostUpdateParams host update params
//
// swagger:model host-update-params
type HostUpdateParams struct {

	// disks selected config
	DisksSelectedConfig []*DiskConfigParams `json:"disks_selected_config"`

	// Allows changing the host's skip_formatting_disks parameter
	DisksSkipFormatting []*DiskSkipFormattingParams `json:"disks_skip_formatting"`

	// host name
	HostName *string `json:"host_name,omitempty"`

	// host role
	// Enum: [auto-assign master worker]
	HostRole *string `json:"host_role,omitempty"`

	// A string which will be used as Authorization Bearer token to fetch the ignition from ignition_endpoint_url.
	IgnitionEndpointToken *string `json:"ignition_endpoint_token,omitempty"`

	// machine config pool name
	MachineConfigPoolName *string `json:"machine_config_pool_name,omitempty"`

	// Labels to be added to the corresponding node.
	NodeLabels []*NodeLabelParams `json:"node_labels"`
}

// Validate validates this host update params
func (m *HostUpdateParams) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

	}

	return nil
}

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

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

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

	}

	return nil
}

var hostUpdateParamsTypeHostRolePropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["auto-assign","master","worker"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		hostUpdateParamsTypeHostRolePropEnum = append(hostUpdateParamsTypeHostRolePropEnum, v)
	}
}

const (

	// HostUpdateParamsHostRoleAutoAssign captures enum value "auto-assign"
	HostUpdateParamsHostRoleAutoAssign string = "auto-assign"

	// HostUpdateParamsHostRoleMaster captures enum value "master"
	HostUpdateParamsHostRoleMaster string = "master"

	// HostUpdateParamsHostRoleWorker captures enum value "worker"
	HostUpdateParamsHostRoleWorker string = "worker"
)

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

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

	// value enum
	if err := m.validateHostRoleEnum("host_role", "body", *m.HostRole); err != nil {
		return err
	}

	return nil
}

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

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

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

	}

	return nil
}

// ContextValidate validate this host update params based on the context it is used
func (m *HostUpdateParams) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *HostUpdateParams) contextValidateDisksSelectedConfig(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *HostUpdateParams) contextValidateDisksSkipFormatting(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *HostUpdateParams) contextValidateNodeLabels(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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