// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// MessagesDhConfigNotModified represents TL type `messages.dhConfigNotModified#c0e24635`.
// Configuring parameters did not change.
//
// See https://core.telegram.org/constructor/messages.dhConfigNotModified for reference.
type MessagesDhConfigNotModified struct {
	// Random sequence of bytes of assigned length
	Random []byte
}

// MessagesDhConfigNotModifiedTypeID is TL type id of MessagesDhConfigNotModified.
const MessagesDhConfigNotModifiedTypeID = 0xc0e24635

// construct implements constructor of MessagesDhConfigClass.
func ( MessagesDhConfigNotModified) () MessagesDhConfigClass { return & }

// Ensuring interfaces in compile-time for MessagesDhConfigNotModified.
var (
	_ bin.Encoder     = &MessagesDhConfigNotModified{}
	_ bin.Decoder     = &MessagesDhConfigNotModified{}
	_ bin.BareEncoder = &MessagesDhConfigNotModified{}
	_ bin.BareDecoder = &MessagesDhConfigNotModified{}

	_ MessagesDhConfigClass = &MessagesDhConfigNotModified{}
)

func ( *MessagesDhConfigNotModified) () bool {
	if  == nil {
		return true
	}
	if !(.Random == nil) {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func ( *MessagesDhConfigNotModified) () string {
	if  == nil {
		return "MessagesDhConfigNotModified(nil)"
	}
	type  MessagesDhConfigNotModified
	return fmt.Sprintf("MessagesDhConfigNotModified%+v", (*))
}

// FillFrom fills MessagesDhConfigNotModified from given interface.
func ( *MessagesDhConfigNotModified) ( interface {
	() ( []byte)
}) {
	.Random = .()
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessagesDhConfigNotModified) () uint32 {
	return MessagesDhConfigNotModifiedTypeID
}

// TypeName returns name of type in TL schema.
func (*MessagesDhConfigNotModified) () string {
	return "messages.dhConfigNotModified"
}

// TypeInfo returns info about TL type.
func ( *MessagesDhConfigNotModified) () tdp.Type {
	 := tdp.Type{
		Name: "messages.dhConfigNotModified",
		ID:   MessagesDhConfigNotModifiedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Random",
			SchemaName: "random",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesDhConfigNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.dhConfigNotModified#c0e24635 as nil")
	}
	.PutID(MessagesDhConfigNotModifiedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesDhConfigNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.dhConfigNotModified#c0e24635 as nil")
	}
	.PutBytes(.Random)
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesDhConfigNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.dhConfigNotModified#c0e24635 to nil")
	}
	if  := .ConsumeID(MessagesDhConfigNotModifiedTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.dhConfigNotModified#c0e24635: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesDhConfigNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.dhConfigNotModified#c0e24635 to nil")
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode messages.dhConfigNotModified#c0e24635: field random: %w", )
		}
		.Random = 
	}
	return nil
}

// GetRandom returns value of Random field.
func ( *MessagesDhConfigNotModified) () ( []byte) {
	if  == nil {
		return
	}
	return .Random
}

// MessagesDhConfig represents TL type `messages.dhConfig#2c221edd`.
// New set of configuring parameters.
//
// See https://core.telegram.org/constructor/messages.dhConfig for reference.
type MessagesDhConfig struct {
	// New value prime, see Wikipedia¹
	//
	// Links:
	//  1) https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
	G int
	// New value primitive root, see Wikipedia¹
	//
	// Links:
	//  1) https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
	P []byte
	// Version of set of parameters
	Version int
	// Random sequence of bytes of assigned length
	Random []byte
}

// MessagesDhConfigTypeID is TL type id of MessagesDhConfig.
const MessagesDhConfigTypeID = 0x2c221edd

// construct implements constructor of MessagesDhConfigClass.
func ( MessagesDhConfig) () MessagesDhConfigClass { return & }

// Ensuring interfaces in compile-time for MessagesDhConfig.
var (
	_ bin.Encoder     = &MessagesDhConfig{}
	_ bin.Decoder     = &MessagesDhConfig{}
	_ bin.BareEncoder = &MessagesDhConfig{}
	_ bin.BareDecoder = &MessagesDhConfig{}

	_ MessagesDhConfigClass = &MessagesDhConfig{}
)

func ( *MessagesDhConfig) () bool {
	if  == nil {
		return true
	}
	if !(.G == 0) {
		return false
	}
	if !(.P == nil) {
		return false
	}
	if !(.Version == 0) {
		return false
	}
	if !(.Random == nil) {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func ( *MessagesDhConfig) () string {
	if  == nil {
		return "MessagesDhConfig(nil)"
	}
	type  MessagesDhConfig
	return fmt.Sprintf("MessagesDhConfig%+v", (*))
}

// FillFrom fills MessagesDhConfig from given interface.
func ( *MessagesDhConfig) ( interface {
	() ( int)
	() ( []byte)
	() ( int)
	() ( []byte)
}) {
	.G = .()
	.P = .()
	.Version = .()
	.Random = .()
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessagesDhConfig) () uint32 {
	return MessagesDhConfigTypeID
}

// TypeName returns name of type in TL schema.
func (*MessagesDhConfig) () string {
	return "messages.dhConfig"
}

// TypeInfo returns info about TL type.
func ( *MessagesDhConfig) () tdp.Type {
	 := tdp.Type{
		Name: "messages.dhConfig",
		ID:   MessagesDhConfigTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "G",
			SchemaName: "g",
		},
		{
			Name:       "P",
			SchemaName: "p",
		},
		{
			Name:       "Version",
			SchemaName: "version",
		},
		{
			Name:       "Random",
			SchemaName: "random",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesDhConfig) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.dhConfig#2c221edd as nil")
	}
	.PutID(MessagesDhConfigTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesDhConfig) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.dhConfig#2c221edd as nil")
	}
	.PutInt(.G)
	.PutBytes(.P)
	.PutInt(.Version)
	.PutBytes(.Random)
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesDhConfig) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.dhConfig#2c221edd to nil")
	}
	if  := .ConsumeID(MessagesDhConfigTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.dhConfig#2c221edd: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesDhConfig) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.dhConfig#2c221edd to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.dhConfig#2c221edd: field g: %w", )
		}
		.G = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode messages.dhConfig#2c221edd: field p: %w", )
		}
		.P = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.dhConfig#2c221edd: field version: %w", )
		}
		.Version = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode messages.dhConfig#2c221edd: field random: %w", )
		}
		.Random = 
	}
	return nil
}

// GetG returns value of G field.
func ( *MessagesDhConfig) () ( int) {
	if  == nil {
		return
	}
	return .G
}

// GetP returns value of P field.
func ( *MessagesDhConfig) () ( []byte) {
	if  == nil {
		return
	}
	return .P
}

// GetVersion returns value of Version field.
func ( *MessagesDhConfig) () ( int) {
	if  == nil {
		return
	}
	return .Version
}

// GetRandom returns value of Random field.
func ( *MessagesDhConfig) () ( []byte) {
	if  == nil {
		return
	}
	return .Random
}

// MessagesDhConfigClassName is schema name of MessagesDhConfigClass.
const MessagesDhConfigClassName = "messages.DhConfig"

// MessagesDhConfigClass represents messages.DhConfig generic type.
//
// See https://core.telegram.org/type/messages.DhConfig for reference.
//
// Example:
//
//	g, err := tg.DecodeMessagesDhConfig(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessagesDhConfigNotModified: // messages.dhConfigNotModified#c0e24635
//	case *tg.MessagesDhConfig: // messages.dhConfig#2c221edd
//	default: panic(v)
//	}
type MessagesDhConfigClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessagesDhConfigClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Random sequence of bytes of assigned length
	GetRandom() (value []byte)
	// AsModified tries to map MessagesDhConfigClass to MessagesDhConfig.
	AsModified() (*MessagesDhConfig, bool)
}

// AsModified tries to map MessagesDhConfigNotModified to MessagesDhConfig.
func ( *MessagesDhConfigNotModified) () (*MessagesDhConfig, bool) {
	return nil, false
}

// AsModified tries to map MessagesDhConfig to MessagesDhConfig.
func ( *MessagesDhConfig) () (*MessagesDhConfig, bool) {
	return , true
}

// DecodeMessagesDhConfig implements binary de-serialization for MessagesDhConfigClass.
func ( *bin.Buffer) (MessagesDhConfigClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case MessagesDhConfigNotModifiedTypeID:
		// Decoding messages.dhConfigNotModified#c0e24635.
		 := MessagesDhConfigNotModified{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode MessagesDhConfigClass: %w", )
		}
		return &, nil
	case MessagesDhConfigTypeID:
		// Decoding messages.dhConfig#2c221edd.
		 := MessagesDhConfig{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode MessagesDhConfigClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode MessagesDhConfigClass: %w", bin.NewUnexpectedID())
	}
}

// MessagesDhConfig boxes the MessagesDhConfigClass providing a helper.
type MessagesDhConfigBox struct {
	DhConfig MessagesDhConfigClass
}

// Decode implements bin.Decoder for MessagesDhConfigBox.
func ( *MessagesDhConfigBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode MessagesDhConfigBox to nil")
	}
	,  := DecodeMessagesDhConfig()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.DhConfig = 
	return nil
}

// Encode implements bin.Encode for MessagesDhConfigBox.
func ( *MessagesDhConfigBox) ( *bin.Buffer) error {
	if  == nil || .DhConfig == nil {
		return fmt.Errorf("unable to encode MessagesDhConfigClass as nil")
	}
	return .DhConfig.Encode()
}