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

// HashicorpCloudPacker20230101VulnerabilityWithImpacts hashicorp cloud packer 20230101 vulnerability with impacts
//
// swagger:model hashicorp.cloud.packer_20230101.VulnerabilityWithImpacts
type HashicorpCloudPacker20230101VulnerabilityWithImpacts struct {

	// impacted builds
	ImpactedBuilds []*HashicorpCloudPacker20230101ImpactedBuild `json:"impacted_builds"`

	// impacted channels
	ImpactedChannels []*HashicorpCloudPacker20230101ImpactedChannel `json:"impacted_channels"`

	// impacted packages
	ImpactedPackages []*HashicorpCloudPacker20230101ImpactedPackage `json:"impacted_packages"`

	// vulnerability
	Vulnerability *HashicorpCloudPacker20230101Vulnerability `json:"vulnerability,omitempty"`
}

// Validate validates this hashicorp cloud packer 20230101 vulnerability with impacts
func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) validateImpactedBuilds(formats strfmt.Registry) error {
	if swag.IsZero(m.ImpactedBuilds) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) validateImpactedChannels(formats strfmt.Registry) error {
	if swag.IsZero(m.ImpactedChannels) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) validateImpactedPackages(formats strfmt.Registry) error {
	if swag.IsZero(m.ImpactedPackages) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) validateVulnerability(formats strfmt.Registry) error {
	if swag.IsZero(m.Vulnerability) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud packer 20230101 vulnerability with impacts based on the context it is used
func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) contextValidateImpactedBuilds(ctx context.Context, formats strfmt.Registry) error {

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

		if m.ImpactedBuilds[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) contextValidateImpactedChannels(ctx context.Context, formats strfmt.Registry) error {

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

		if m.ImpactedChannels[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) contextValidateImpactedPackages(ctx context.Context, formats strfmt.Registry) error {

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

		if m.ImpactedPackages[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101VulnerabilityWithImpacts) contextValidateVulnerability(ctx context.Context, formats strfmt.Registry) error {

	if m.Vulnerability != nil {

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

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

	return nil
}

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

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