// 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"
	cloud "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
)

// HashicorpCloudPacker20230101EnforcedBlock hashicorp cloud packer 20230101 enforced block
//
// swagger:model hashicorp.cloud.packer_20230101.EnforcedBlock
type HashicorpCloudPacker20230101EnforcedBlock struct {

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

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

	// A key:value map for custom, user-settable metadata
	Labels map[string]string `json:"labels,omitempty"`

	// Optional: Only populated when fetching block by ID
	// Current version of the enforced block
	LatestVersion *HashicorpCloudPacker20230101EnforcedBlockVersion `json:"latest_version,omitempty"`

	// Location information (organization_id, project_id)
	Location *cloud.HashicorpCloudLocationLocation `json:"location,omitempty"`

	// User defined name of the enforced block
	Name string `json:"name,omitempty"`

	// The human-readable identifier in the platform
	ResourceName string `json:"resource_name,omitempty"`

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

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

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

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

	if err := m.validateLocation(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 *HashicorpCloudPacker20230101EnforcedBlock) 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 *HashicorpCloudPacker20230101EnforcedBlock) validateLatestVersion(formats strfmt.Registry) error {
	if swag.IsZero(m.LatestVersion) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101EnforcedBlock) validateLocation(formats strfmt.Registry) error {
	if swag.IsZero(m.Location) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101EnforcedBlock) 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 based on the context it is used
func (m *HashicorpCloudPacker20230101EnforcedBlock) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudPacker20230101EnforcedBlock) contextValidateLatestVersion(ctx context.Context, formats strfmt.Registry) error {

	if m.LatestVersion != nil {

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

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

	return nil
}

func (m *HashicorpCloudPacker20230101EnforcedBlock) contextValidateLocation(ctx context.Context, formats strfmt.Registry) error {

	if m.Location != nil {

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

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

	return nil
}

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

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