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

// HashicorpCloudPacker20230101EnforcedBlockLinkedBucket EnforcedBlockLinkedBucket contains the full bucket information for a linked bucket
//
// swagger:model hashicorp.cloud.packer_20230101.EnforcedBlockLinkedBucket
type HashicorpCloudPacker20230101EnforcedBlockLinkedBucket struct {

	// The full bucket object
	Bucket *HashicorpCloudPacker20230101Bucket `json:"bucket,omitempty"`

	// When the link was created
	// Format: date-time
	CreatedAt strfmt.DateTime `json:"created_at,omitempty"`

	// The enforced block ID this bucket is linked to
	EnforcedBlockID string `json:"enforced_block_id,omitempty"`

	// The enforced block version ID this bucket is linked to
	EnforcedBlockVersionID string `json:"enforced_block_version_id,omitempty"`

	// The link ID (ULID)
	ID string `json:"id,omitempty"`
}

// Validate validates this hashicorp cloud packer 20230101 enforced block linked bucket
func (m *HashicorpCloudPacker20230101EnforcedBlockLinkedBucket) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudPacker20230101EnforcedBlockLinkedBucket) validateBucket(formats strfmt.Registry) error {
	if swag.IsZero(m.Bucket) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101EnforcedBlockLinkedBucket) validateCreatedAt(formats strfmt.Registry) error {
	if swag.IsZero(m.CreatedAt) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *HashicorpCloudPacker20230101EnforcedBlockLinkedBucket) contextValidateBucket(ctx context.Context, formats strfmt.Registry) error {

	if m.Bucket != nil {

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

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

	return nil
}

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

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