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

// HashicorpCloudPacker20230101CreateEnforcedBlockVersionBody hashicorp cloud packer 20230101 create enforced block version body
//
// swagger:model hashicorp.cloud.packer_20230101.CreateEnforcedBlockVersionBody
type HashicorpCloudPacker20230101CreateEnforcedBlockVersionBody struct {

	// Optional additional description for more detailed documentation
	AdditionalDescription string `json:"additional_description,omitempty"`

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

	// The type of Packer configuration template (HCL2 or JSON)
	TemplateType *HashicorpCloudPacker20230101TemplateType `json:"template_type,omitempty"`

	// Version label for this enforced block version
	Version string `json:"version,omitempty"`
}

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

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

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

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

// ContextValidate validate this hashicorp cloud packer 20230101 create enforced block version body based on the context it is used
func (m *HashicorpCloudPacker20230101CreateEnforcedBlockVersionBody) 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 *HashicorpCloudPacker20230101CreateEnforcedBlockVersionBody) 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 *HashicorpCloudPacker20230101CreateEnforcedBlockVersionBody) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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