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

// HashicorpCloudPackerBucketAncestryParent hashicorp cloud packer bucket ancestry parent
//
// swagger:model hashicorp.cloud.packer.BucketAncestry.Parent
type HashicorpCloudPackerBucketAncestryParent struct {

	// The parent bucket slug.
	BucketSlug string `json:"bucket_slug,omitempty"`

	// The image channel associated with this relationship.
	Channel string `json:"channel,omitempty"`

	// The iteration currently assigned to the channel associated with the ancestry relationship.
	ChannelIteration *HashicorpCloudPackerBucketAncestryParentChannelIteration `json:"channel_iteration,omitempty"`

	// The parent iteration fingerprint.
	IterationFingerprint string `json:"iteration_fingerprint,omitempty"`

	// The parent iteration ULID.
	IterationID string `json:"iteration_id,omitempty"`

	// The parent iteration incremental version.
	IterationIncrementalVersion int32 `json:"iteration_incremental_version,omitempty"`
}

// Validate validates this hashicorp cloud packer bucket ancestry parent
func (m *HashicorpCloudPackerBucketAncestryParent) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *HashicorpCloudPackerBucketAncestryParent) validateChannelIteration(formats strfmt.Registry) error {
	if swag.IsZero(m.ChannelIteration) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *HashicorpCloudPackerBucketAncestryParent) contextValidateChannelIteration(ctx context.Context, formats strfmt.Registry) error {

	if m.ChannelIteration != nil {

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

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

	return nil
}

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

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