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

// HashicorpCloudPacker20230101Package hashicorp cloud packer 20230101 package
//
// swagger:model hashicorp.cloud.packer_20230101.Package
type HashicorpCloudPacker20230101Package struct {

	// Optional: only populated in ListBucketPackagesWithVulnerabilities
	// Unique identifier (ULID) of the build that contains this package.
	BuildID string `json:"build_id,omitempty"`

	// Optional: only populated in ListBucketPackagesWithVulnerabilities
	// Component type of the build (e.g., "amazon-ebs", "azure-arm").
	BuildName string `json:"build_name,omitempty"`

	// Optional: only populated in ListBucketPackagesWithVulnerabilities
	// Unique identifier (ULID) of the channel that contains this package.
	ChannelID string `json:"channel_id,omitempty"`

	// Optional: only populated in ListBucketPackagesWithVulnerabilities
	// Slug name of the channel that contains this package.
	ChannelName string `json:"channel_name,omitempty"`

	// Name of the package.
	Name string `json:"name,omitempty"`

	// Package URL (purl) that uniquely identifies the package.
	Purl string `json:"purl,omitempty"`

	// List of SBOMs that reference this package.
	Sboms []*HashicorpCloudPacker20230101Sbom `json:"sboms"`

	// Version of the package.
	Version string `json:"version,omitempty"`

	// Optional: only populated in ListBucketPackagesWithVulnerabilities
	// Vulnerability details for this package, including scan timestamp and list of vulnerabilities.
	VulnDetails []*HashicorpCloudPacker20230101VulnerabilityDetails `json:"vuln_details"`
}

// Validate validates this hashicorp cloud packer 20230101 package
func (m *HashicorpCloudPacker20230101Package) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudPacker20230101Package) validateSboms(formats strfmt.Registry) error {
	if swag.IsZero(m.Sboms) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101Package) validateVulnDetails(formats strfmt.Registry) error {
	if swag.IsZero(m.VulnDetails) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

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

func (m *HashicorpCloudPacker20230101Package) contextValidateSboms(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Sboms[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudPacker20230101Package) contextValidateVulnDetails(ctx context.Context, formats strfmt.Registry) error {

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

		if m.VulnDetails[i] != nil {

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

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

	}

	return nil
}

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

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