// Code generated by gotdgen, DO NOT EDIT.

package mt

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{}
)

// ServerDHParamsFail represents TL type `server_DH_params_fail#79cb045d`.
type ServerDHParamsFail struct {
	// Nonce field of ServerDHParamsFail.
	Nonce bin.Int128
	// ServerNonce field of ServerDHParamsFail.
	ServerNonce bin.Int128
	// NewNonceHash field of ServerDHParamsFail.
	NewNonceHash bin.Int128
}

// ServerDHParamsFailTypeID is TL type id of ServerDHParamsFail.
const ServerDHParamsFailTypeID = 0x79cb045d

// construct implements constructor of ServerDHParamsClass.
func ( ServerDHParamsFail) () ServerDHParamsClass { return & }

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

	_ ServerDHParamsClass = &ServerDHParamsFail{}
)

func ( *ServerDHParamsFail) () bool {
	if  == nil {
		return true
	}
	if !(.Nonce == bin.Int128{}) {
		return false
	}
	if !(.ServerNonce == bin.Int128{}) {
		return false
	}
	if !(.NewNonceHash == bin.Int128{}) {
		return false
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*ServerDHParamsFail) () string {
	return "server_DH_params_fail"
}

// TypeInfo returns info about TL type.
func ( *ServerDHParamsFail) () tdp.Type {
	 := tdp.Type{
		Name: "server_DH_params_fail",
		ID:   ServerDHParamsFailTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Nonce",
			SchemaName: "nonce",
		},
		{
			Name:       "ServerNonce",
			SchemaName: "server_nonce",
		},
		{
			Name:       "NewNonceHash",
			SchemaName: "new_nonce_hash",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ServerDHParamsFail) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode server_DH_params_fail#79cb045d as nil")
	}
	.PutID(ServerDHParamsFailTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ServerDHParamsFail) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode server_DH_params_fail#79cb045d as nil")
	}
	.PutInt128(.Nonce)
	.PutInt128(.ServerNonce)
	.PutInt128(.NewNonceHash)
	return nil
}

// Decode implements bin.Decoder.
func ( *ServerDHParamsFail) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode server_DH_params_fail#79cb045d to nil")
	}
	if  := .ConsumeID(ServerDHParamsFailTypeID);  != nil {
		return fmt.Errorf("unable to decode server_DH_params_fail#79cb045d: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ServerDHParamsFail) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode server_DH_params_fail#79cb045d to nil")
	}
	{
		,  := .Int128()
		if  != nil {
			return fmt.Errorf("unable to decode server_DH_params_fail#79cb045d: field nonce: %w", )
		}
		.Nonce = 
	}
	{
		,  := .Int128()
		if  != nil {
			return fmt.Errorf("unable to decode server_DH_params_fail#79cb045d: field server_nonce: %w", )
		}
		.ServerNonce = 
	}
	{
		,  := .Int128()
		if  != nil {
			return fmt.Errorf("unable to decode server_DH_params_fail#79cb045d: field new_nonce_hash: %w", )
		}
		.NewNonceHash = 
	}
	return nil
}

// GetNonce returns value of Nonce field.
func ( *ServerDHParamsFail) () ( bin.Int128) {
	if  == nil {
		return
	}
	return .Nonce
}

// GetServerNonce returns value of ServerNonce field.
func ( *ServerDHParamsFail) () ( bin.Int128) {
	if  == nil {
		return
	}
	return .ServerNonce
}

// GetNewNonceHash returns value of NewNonceHash field.
func ( *ServerDHParamsFail) () ( bin.Int128) {
	if  == nil {
		return
	}
	return .NewNonceHash
}

// ServerDHParamsOk represents TL type `server_DH_params_ok#d0e8075c`.
type ServerDHParamsOk struct {
	// Nonce field of ServerDHParamsOk.
	Nonce bin.Int128
	// ServerNonce field of ServerDHParamsOk.
	ServerNonce bin.Int128
	// EncryptedAnswer field of ServerDHParamsOk.
	EncryptedAnswer []byte
}

// ServerDHParamsOkTypeID is TL type id of ServerDHParamsOk.
const ServerDHParamsOkTypeID = 0xd0e8075c

// construct implements constructor of ServerDHParamsClass.
func ( ServerDHParamsOk) () ServerDHParamsClass { return & }

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

	_ ServerDHParamsClass = &ServerDHParamsOk{}
)

func ( *ServerDHParamsOk) () bool {
	if  == nil {
		return true
	}
	if !(.Nonce == bin.Int128{}) {
		return false
	}
	if !(.ServerNonce == bin.Int128{}) {
		return false
	}
	if !(.EncryptedAnswer == nil) {
		return false
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*ServerDHParamsOk) () string {
	return "server_DH_params_ok"
}

// TypeInfo returns info about TL type.
func ( *ServerDHParamsOk) () tdp.Type {
	 := tdp.Type{
		Name: "server_DH_params_ok",
		ID:   ServerDHParamsOkTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Nonce",
			SchemaName: "nonce",
		},
		{
			Name:       "ServerNonce",
			SchemaName: "server_nonce",
		},
		{
			Name:       "EncryptedAnswer",
			SchemaName: "encrypted_answer",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ServerDHParamsOk) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode server_DH_params_ok#d0e8075c as nil")
	}
	.PutID(ServerDHParamsOkTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ServerDHParamsOk) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode server_DH_params_ok#d0e8075c as nil")
	}
	.PutInt128(.Nonce)
	.PutInt128(.ServerNonce)
	.PutBytes(.EncryptedAnswer)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ServerDHParamsOk) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode server_DH_params_ok#d0e8075c to nil")
	}
	{
		,  := .Int128()
		if  != nil {
			return fmt.Errorf("unable to decode server_DH_params_ok#d0e8075c: field nonce: %w", )
		}
		.Nonce = 
	}
	{
		,  := .Int128()
		if  != nil {
			return fmt.Errorf("unable to decode server_DH_params_ok#d0e8075c: field server_nonce: %w", )
		}
		.ServerNonce = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode server_DH_params_ok#d0e8075c: field encrypted_answer: %w", )
		}
		.EncryptedAnswer = 
	}
	return nil
}

// GetNonce returns value of Nonce field.
func ( *ServerDHParamsOk) () ( bin.Int128) {
	if  == nil {
		return
	}
	return .Nonce
}

// GetServerNonce returns value of ServerNonce field.
func ( *ServerDHParamsOk) () ( bin.Int128) {
	if  == nil {
		return
	}
	return .ServerNonce
}

// GetEncryptedAnswer returns value of EncryptedAnswer field.
func ( *ServerDHParamsOk) () ( []byte) {
	if  == nil {
		return
	}
	return .EncryptedAnswer
}

// ServerDHParamsClassName is schema name of ServerDHParamsClass.
const ServerDHParamsClassName = "Server_DH_Params"

// ServerDHParamsClass represents Server_DH_Params generic type.
//
// Example:
//
//	g, err := mt.DecodeServerDHParams(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *mt.ServerDHParamsFail: // server_DH_params_fail#79cb045d
//	case *mt.ServerDHParamsOk: // server_DH_params_ok#d0e8075c
//	default: panic(v)
//	}
type ServerDHParamsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ServerDHParamsClass

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

	// Nonce field of ServerDHParamsFail.
	GetNonce() (value bin.Int128)
	// ServerNonce field of ServerDHParamsFail.
	GetServerNonce() (value bin.Int128)
}

// DecodeServerDHParams implements binary de-serialization for ServerDHParamsClass.
func ( *bin.Buffer) (ServerDHParamsClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ServerDHParamsFailTypeID:
		// Decoding server_DH_params_fail#79cb045d.
		 := ServerDHParamsFail{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ServerDHParamsClass: %w", )
		}
		return &, nil
	case ServerDHParamsOkTypeID:
		// Decoding server_DH_params_ok#d0e8075c.
		 := ServerDHParamsOk{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ServerDHParamsClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ServerDHParamsClass: %w", bin.NewUnexpectedID())
	}
}

// ServerDHParams boxes the ServerDHParamsClass providing a helper.
type ServerDHParamsBox struct {
	Server_DH_Params ServerDHParamsClass
}

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

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