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

// HashicorpCloudPacker20230101EnforcedBlockVersion hashicorp cloud packer 20230101 enforced block version
//
// swagger:model hashicorp.cloud.packer_20230101.EnforcedBlockVersion
type HashicorpCloudPacker20230101EnforcedBlockVersion struct {

	// Optional additional description
	AdditionalDescription string `json:"additional_description,omitempty"`

	// The actual Packer block configuration content
	BlockContent string `json:"block_content,omitempty"`

	// Created datetime
	// Format: date-time
	CreatedAt strfmt.DateTime `json:"created_at,omitempty"`

	// ID of the enforced block this version belongs to
	EnforcedBlockID string `json:"enforced_block_id,omitempty"`

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

	// The type of Packer configuration template
	TemplateType *HashicorpCloudPacker20230101TemplateType `json:"template_type,omitempty"`

	// Last updated datetime
	// Format: date-time
	UpdatedAt strfmt.DateTime `json:"updated_at,omitempty"`

	// version of the enforced block
	Version string `json:"version,omitempty"`
}

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

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

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

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

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

func (m *HashicorpCloudPacker20230101EnforcedBlockVersion) 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
}

func (m *HashicorpCloudPacker20230101EnforcedBlockVersion) validateTemplateType(formats strfmt.Registry) error {
	if swag.IsZero(m.TemplateType) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101EnforcedBlockVersion) validateUpdatedAt(formats strfmt.Registry) error {
	if swag.IsZero(m.UpdatedAt) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *HashicorpCloudPacker20230101EnforcedBlockVersion) contextValidateTemplateType(ctx context.Context, formats strfmt.Registry) error {

	if m.TemplateType != nil {

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

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

	return nil
}

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

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