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

// HashicorpCloudPacker20230101ChannelAssignment hashicorp cloud packer 20230101 channel assignment
//
// swagger:model hashicorp.cloud.packer_20230101.ChannelAssignment
type HashicorpCloudPacker20230101ChannelAssignment struct {

	// When the version assignment happened.
	// Format: date-time
	AssignedAt strfmt.DateTime `json:"assigned_at,omitempty"`

	// The user who assigned this version.
	AuthorID string `json:"author_id,omitempty"`

	// The assigned version.
	Version *HashicorpCloudPacker20230101Version `json:"version,omitempty"`
}

// Validate validates this hashicorp cloud packer 20230101 channel assignment
func (m *HashicorpCloudPacker20230101ChannelAssignment) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudPacker20230101ChannelAssignment) validateAssignedAt(formats strfmt.Registry) error {
	if swag.IsZero(m.AssignedAt) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudPacker20230101ChannelAssignment) validateVersion(formats strfmt.Registry) error {
	if swag.IsZero(m.Version) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *HashicorpCloudPacker20230101ChannelAssignment) contextValidateVersion(ctx context.Context, formats strfmt.Registry) error {

	if m.Version != nil {

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

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

	return nil
}

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

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