// Code generated by go-swagger; DO NOT EDIT.

package model

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

// DataflowTopicPartitionConfig dataflow topic partition config
//
// swagger:model dataflowTopicPartitionConfig
type DataflowTopicPartitionConfig struct {

	// default topic
	DefaultTopic string `json:"default_topic,omitempty"`

	// dispatch type
	DispatchType *DataflowDispatchType `json:"dispatch_type,omitempty"`

	// partition dispatcher
	PartitionDispatcher *DataflowPartitionDispatcher `json:"partition_dispatcher,omitempty"`

	// partition num
	PartitionNum int64 `json:"partition_num,omitempty"`

	// replication factor
	ReplicationFactor int64 `json:"replication_factor,omitempty"`

	// separator
	Separator string `json:"separator,omitempty"`

	// topic prefix
	TopicPrefix string `json:"topic_prefix,omitempty"`

	// topic suffix
	TopicSuffix string `json:"topic_suffix,omitempty"`
}

// Validate validates this dataflow topic partition config
func (m *DataflowTopicPartitionConfig) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *DataflowTopicPartitionConfig) validateDispatchType(formats strfmt.Registry) error {
	if swag.IsZero(m.DispatchType) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowTopicPartitionConfig) validatePartitionDispatcher(formats strfmt.Registry) error {
	if swag.IsZero(m.PartitionDispatcher) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this dataflow topic partition config based on the context it is used
func (m *DataflowTopicPartitionConfig) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *DataflowTopicPartitionConfig) contextValidateDispatchType(ctx context.Context, formats strfmt.Registry) error {

	if m.DispatchType != nil {

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

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

	return nil
}

func (m *DataflowTopicPartitionConfig) contextValidatePartitionDispatcher(ctx context.Context, formats strfmt.Registry) error {

	if m.PartitionDispatcher != nil {

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

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

	return nil
}

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

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