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

// HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse hashicorp cloud packer 20230101 list bucket packages vulnerability summary response
//
// swagger:model hashicorp.cloud.packer_20230101.ListBucketPackagesVulnerabilitySummaryResponse
type HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse struct {

	// channels by criticality
	ChannelsByCriticality []*HashicorpCloudPacker20230101ChannelVulnerabilityCount `json:"channels_by_criticality"`

	// packages by criticality
	PackagesByCriticality []*HashicorpCloudPacker20230101PackageVulnerabilityCount `json:"packages_by_criticality"`

	// total by criticality
	TotalByCriticality []*HashicorpCloudPacker20230101CriticalityCount `json:"total_by_criticality"`
}

// Validate validates this hashicorp cloud packer 20230101 list bucket packages vulnerability summary response
func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) validateChannelsByCriticality(formats strfmt.Registry) error {
	if swag.IsZero(m.ChannelsByCriticality) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) validatePackagesByCriticality(formats strfmt.Registry) error {
	if swag.IsZero(m.PackagesByCriticality) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) validateTotalByCriticality(formats strfmt.Registry) error {
	if swag.IsZero(m.TotalByCriticality) { // not required
		return nil
	}

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

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

	}

	return nil
}

// ContextValidate validate this hashicorp cloud packer 20230101 list bucket packages vulnerability summary response based on the context it is used
func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) contextValidateChannelsByCriticality(ctx context.Context, formats strfmt.Registry) error {

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

		if m.ChannelsByCriticality[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) contextValidatePackagesByCriticality(ctx context.Context, formats strfmt.Registry) error {

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

		if m.PackagesByCriticality[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101ListBucketPackagesVulnerabilitySummaryResponse) contextValidateTotalByCriticality(ctx context.Context, formats strfmt.Registry) error {

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

		if m.TotalByCriticality[i] != nil {

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

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

	}

	return nil
}

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

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