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

// TonConnectRequest represents TL type `tonConnectRequest#a15f8513`.
//
// See https://core.telegram.org/constructor/tonConnectRequest for reference.
type TonConnectRequest struct {
	// Flags field of TonConnectRequest.
	Flags bin.Fields
	// SessionID field of TonConnectRequest.
	SessionID int64
	// MsgID field of TonConnectRequest.
	MsgID int
	// Body field of TonConnectRequest.
	Body []byte
	// Expires field of TonConnectRequest.
	Expires int
	// Topic field of TonConnectRequest.
	//
	// Use SetTopic and GetTopic helpers.
	Topic string
	// TraceID field of TonConnectRequest.
	//
	// Use SetTraceID and GetTraceID helpers.
	TraceID string
}

// TonConnectRequestTypeID is TL type id of TonConnectRequest.
const TonConnectRequestTypeID = 0xa15f8513

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

func ( *TonConnectRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.SessionID == 0) {
		return false
	}
	if !(.MsgID == 0) {
		return false
	}
	if !(.Body == nil) {
		return false
	}
	if !(.Expires == 0) {
		return false
	}
	if !(.Topic == "") {
		return false
	}
	if !(.TraceID == "") {
		return false
	}

	return true
}

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

// FillFrom fills TonConnectRequest from given interface.
func ( *TonConnectRequest) ( interface {
	() ( int64)
	() ( int)
	() ( []byte)
	() ( int)
	() ( string,  bool)
	() ( string,  bool)
}) {
	.SessionID = .()
	.MsgID = .()
	.Body = .()
	.Expires = .()
	if ,  := .();  {
		.Topic = 
	}

	if ,  := .();  {
		.TraceID = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *TonConnectRequest) () tdp.Type {
	 := tdp.Type{
		Name: "tonConnectRequest",
		ID:   TonConnectRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "SessionID",
			SchemaName: "session_id",
		},
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
		},
		{
			Name:       "Body",
			SchemaName: "body",
		},
		{
			Name:       "Expires",
			SchemaName: "expires",
		},
		{
			Name:       "Topic",
			SchemaName: "topic",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "TraceID",
			SchemaName: "trace_id",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *TonConnectRequest) () {
	if !(.Topic == "") {
		.Flags.Set(0)
	}
	if !(.TraceID == "") {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *TonConnectRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode tonConnectRequest#a15f8513 as nil")
	}
	.PutID(TonConnectRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *TonConnectRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode tonConnectRequest#a15f8513 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode tonConnectRequest#a15f8513: field flags: %w", )
	}
	.PutLong(.SessionID)
	.PutInt(.MsgID)
	.PutBytes(.Body)
	.PutInt(.Expires)
	if .Flags.Has(0) {
		.PutString(.Topic)
	}
	if .Flags.Has(1) {
		.PutString(.TraceID)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *TonConnectRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode tonConnectRequest#a15f8513 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field session_id: %w", )
		}
		.SessionID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field msg_id: %w", )
		}
		.MsgID = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field body: %w", )
		}
		.Body = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field expires: %w", )
		}
		.Expires = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field topic: %w", )
		}
		.Topic = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectRequest#a15f8513: field trace_id: %w", )
		}
		.TraceID = 
	}
	return nil
}

// GetSessionID returns value of SessionID field.
func ( *TonConnectRequest) () ( int64) {
	if  == nil {
		return
	}
	return .SessionID
}

// GetMsgID returns value of MsgID field.
func ( *TonConnectRequest) () ( int) {
	if  == nil {
		return
	}
	return .MsgID
}

// GetBody returns value of Body field.
func ( *TonConnectRequest) () ( []byte) {
	if  == nil {
		return
	}
	return .Body
}

// GetExpires returns value of Expires field.
func ( *TonConnectRequest) () ( int) {
	if  == nil {
		return
	}
	return .Expires
}

// SetTopic sets value of Topic conditional field.
func ( *TonConnectRequest) ( string) {
	.Flags.Set(0)
	.Topic = 
}

// GetTopic returns value of Topic conditional field and
// boolean which is true if field was set.
func ( *TonConnectRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Topic, true
}

// SetTraceID sets value of TraceID conditional field.
func ( *TonConnectRequest) ( string) {
	.Flags.Set(1)
	.TraceID = 
}

// GetTraceID returns value of TraceID conditional field and
// boolean which is true if field was set.
func ( *TonConnectRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .TraceID, true
}