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

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

// HashicorpCloudPacker20230101ExternalArtifactVersion hashicorp cloud packer 20230101 external artifact version
//
// swagger:model hashicorp.cloud.packer_20230101.ExternalArtifactVersion
type HashicorpCloudPacker20230101ExternalArtifactVersion struct {

	// Name of the author who created this version.
	AuthorID string `json:"author_id,omitempty"`

	// Fingerprint of the version
	Fingerprint string `json:"fingerprint,omitempty"`

	// Unique identifier (ULID).
	ID string `json:"id,omitempty"`

	// Human-readable name for the bucket that this version is associated with.
	Name string `json:"name,omitempty"`

	// Who revoked this version. For human authors (e.g. HCP Portal) this will be
	// an email address. For machine authors using service principals, this is
	// the customer-chosen name for this service principal.
	RevocationAuthor string `json:"revocation_author,omitempty"`

	// Short explanation of why this version was revoked.
	RevocationMessage string `json:"revocation_message,omitempty"`

	// Revocation type is 'manual' when the version is revoked directly or
	// 'inherited' when the version inherits a revocation from an upstream
	// ancestor.
	RevocationType *HashicorpCloudPacker20230101RevocationType `json:"revocation_type,omitempty"`

	// Datetime from when the version is revoked an no longer trusted to be secure.
	// Format: date-time
	RevokeAt strfmt.DateTime `json:"revoke_at,omitempty"`

	// Current state of the version.
	Status *HashicorpCloudPacker20230101VersionStatus `json:"status,omitempty"`
}

// Validate validates this hashicorp cloud packer 20230101 external artifact version
func (m *HashicorpCloudPacker20230101ExternalArtifactVersion) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *HashicorpCloudPacker20230101ExternalArtifactVersion) validateRevocationType(formats strfmt.Registry) error {
	if swag.IsZero(m.RevocationType) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101ExternalArtifactVersion) validateRevokeAt(formats strfmt.Registry) error {
	if swag.IsZero(m.RevokeAt) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101ExternalArtifactVersion) validateStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.Status) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *HashicorpCloudPacker20230101ExternalArtifactVersion) contextValidateRevocationType(ctx context.Context, formats strfmt.Registry) error {

	if m.RevocationType != nil {

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

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

	return nil
}

func (m *HashicorpCloudPacker20230101ExternalArtifactVersion) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {

	if m.Status != nil {

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

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

	return nil
}

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

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