// 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"
	"github.com/go-openapi/validate"
)

// PVMInstanceReferenceV2 p VM instance reference v2
//
// swagger:model PVMInstanceReferenceV2
type PVMInstanceReferenceV2 struct {

	// The pvm instance server configuration
	Configuration *PVMInstanceConfiguration `json:"configuration,omitempty"`

	// The pvm instance cores information
	// Required: true
	Cores *PVMInstanceCores `json:"cores"`

	// Date/Time of PVM creation
	// Format: date-time
	CreationDate strfmt.DateTime `json:"creationDate,omitempty"`

	// The pvm instance deployment information
	// Required: true
	Deployment *PvmInstanceDeployment `json:"deployment"`

	// health
	Health *PVMInstanceV2Health `json:"health,omitempty"`

	// The pvm instance host information
	Host *PvmInstanceHost `json:"host,omitempty"`

	// Link to Cloud Instance resource
	// Required: true
	Href *string `json:"href"`

	// PCloud PVM Instance ID
	// Required: true
	ID *string `json:"id"`

	// The pvm instance memory information
	// Required: true
	Memory *PVMInstanceMemory `json:"memory"`

	// Name of the server
	// Required: true
	Name *string `json:"name"`

	// The pvm instance network ports information
	// Required: true
	NetworkPorts []*PVMInstanceV2NetworkPort `json:"networkPorts"`

	// The pvm instance OS system information
	// Required: true
	OperatingSystem *PVMInstanceOperatingSystem `json:"operatingSystem"`

	// The pvm instance placement group information
	PlacementGroup *PvmInstancePlacementGroup `json:"placementGroup,omitempty"`

	// The status of the instance
	// Required: true
	Status *string `json:"status"`

	// The pvm instance virtual CPU information
	VirtualCores *PVMInstanceVirtualCores `json:"virtualCores,omitempty"`
}

// Validate validates this p VM instance reference v2
func (m *PVMInstanceReferenceV2) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) validateCores(formats strfmt.Registry) error {

	if err := validate.Required("cores", "body", m.Cores); err != nil {
		return err
	}

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

	return nil
}

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

	if err := validate.FormatOf("creationDate", "body", "date-time", m.CreationDate.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *PVMInstanceReferenceV2) validateDeployment(formats strfmt.Registry) error {

	if err := validate.Required("deployment", "body", m.Deployment); err != nil {
		return err
	}

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) validateHref(formats strfmt.Registry) error {

	if err := validate.Required("href", "body", m.Href); err != nil {
		return err
	}

	return nil
}

func (m *PVMInstanceReferenceV2) validateID(formats strfmt.Registry) error {

	if err := validate.Required("id", "body", m.ID); err != nil {
		return err
	}

	return nil
}

func (m *PVMInstanceReferenceV2) validateMemory(formats strfmt.Registry) error {

	if err := validate.Required("memory", "body", m.Memory); err != nil {
		return err
	}

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

	return nil
}

func (m *PVMInstanceReferenceV2) validateName(formats strfmt.Registry) error {

	if err := validate.Required("name", "body", m.Name); err != nil {
		return err
	}

	return nil
}

func (m *PVMInstanceReferenceV2) validateNetworkPorts(formats strfmt.Registry) error {

	if err := validate.Required("networkPorts", "body", m.NetworkPorts); err != nil {
		return err
	}

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

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

	}

	return nil
}

func (m *PVMInstanceReferenceV2) validateOperatingSystem(formats strfmt.Registry) error {

	if err := validate.Required("operatingSystem", "body", m.OperatingSystem); err != nil {
		return err
	}

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

	return nil
}

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) validateStatus(formats strfmt.Registry) error {

	if err := validate.Required("status", "body", m.Status); err != nil {
		return err
	}

	return nil
}

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

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

	return nil
}

// ContextValidate validate this p VM instance reference v2 based on the context it is used
func (m *PVMInstanceReferenceV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

func (m *PVMInstanceReferenceV2) contextValidateConfiguration(ctx context.Context, formats strfmt.Registry) error {

	if m.Configuration != nil {

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateCores(ctx context.Context, formats strfmt.Registry) error {

	if m.Cores != nil {

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateDeployment(ctx context.Context, formats strfmt.Registry) error {

	if m.Deployment != nil {

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateHealth(ctx context.Context, formats strfmt.Registry) error {

	if m.Health != nil {

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateHost(ctx context.Context, formats strfmt.Registry) error {

	if m.Host != nil {

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateMemory(ctx context.Context, formats strfmt.Registry) error {

	if m.Memory != nil {

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateNetworkPorts(ctx context.Context, formats strfmt.Registry) error {

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

		if m.NetworkPorts[i] != nil {

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

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

	}

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateOperatingSystem(ctx context.Context, formats strfmt.Registry) error {

	if m.OperatingSystem != nil {

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidatePlacementGroup(ctx context.Context, formats strfmt.Registry) error {

	if m.PlacementGroup != nil {

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

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

	return nil
}

func (m *PVMInstanceReferenceV2) contextValidateVirtualCores(ctx context.Context, formats strfmt.Registry) error {

	if m.VirtualCores != nil {

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

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

	return nil
}

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

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