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

// TonConnectSession represents TL type `tonConnectSession#126556c6`.
//
// See https://core.telegram.org/constructor/tonConnectSession for reference.
type TonConnectSession struct {
	// Flags field of TonConnectSession.
	Flags bin.Fields
	// Pending field of TonConnectSession.
	Pending bool
	// Closing field of TonConnectSession.
	Closing bool
	// Closed field of TonConnectSession.
	Closed bool
	// ID field of TonConnectSession.
	ID int64
	// DappClientID field of TonConnectSession.
	DappClientID string
	// ClientID field of TonConnectSession.
	//
	// Use SetClientID and GetClientID helpers.
	ClientID string
	// Nonce field of TonConnectSession.
	Nonce []byte
	// Manifest field of TonConnectSession.
	//
	// Use SetManifest and GetManifest helpers.
	Manifest TonConnectManifest
	// ManifestError field of TonConnectSession.
	//
	// Use SetManifestError and GetManifestError helpers.
	ManifestError int
	// Date field of TonConnectSession.
	Date int
}

// TonConnectSessionTypeID is TL type id of TonConnectSession.
const TonConnectSessionTypeID = 0x126556c6

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

func ( *TonConnectSession) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Pending == false) {
		return false
	}
	if !(.Closing == false) {
		return false
	}
	if !(.Closed == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.DappClientID == "") {
		return false
	}
	if !(.ClientID == "") {
		return false
	}
	if !(.Nonce == nil) {
		return false
	}
	if !(.Manifest.Zero()) {
		return false
	}
	if !(.ManifestError == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}

	return true
}

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

// FillFrom fills TonConnectSession from given interface.
func ( *TonConnectSession) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int64)
	() ( string)
	() ( string,  bool)
	() ( []byte)
	() ( TonConnectManifest,  bool)
	() ( int,  bool)
	() ( int)
}) {
	.Pending = .()
	.Closing = .()
	.Closed = .()
	.ID = .()
	.DappClientID = .()
	if ,  := .();  {
		.ClientID = 
	}

	.Nonce = .()
	if ,  := .();  {
		.Manifest = 
	}

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

	.Date = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *TonConnectSession) () tdp.Type {
	 := tdp.Type{
		Name: "tonConnectSession",
		ID:   TonConnectSessionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Pending",
			SchemaName: "pending",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Closing",
			SchemaName: "closing",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Closed",
			SchemaName: "closed",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "DappClientID",
			SchemaName: "dapp_client_id",
		},
		{
			Name:       "ClientID",
			SchemaName: "client_id",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Nonce",
			SchemaName: "nonce",
		},
		{
			Name:       "Manifest",
			SchemaName: "manifest",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ManifestError",
			SchemaName: "manifest_error",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *TonConnectSession) () {
	if !(.Pending == false) {
		.Flags.Set(0)
	}
	if !(.Closing == false) {
		.Flags.Set(1)
	}
	if !(.Closed == false) {
		.Flags.Set(2)
	}
	if !(.ClientID == "") {
		.Flags.Set(3)
	}
	if !(.Manifest.Zero()) {
		.Flags.Set(4)
	}
	if !(.ManifestError == 0) {
		.Flags.Set(5)
	}
}

// Encode implements bin.Encoder.
func ( *TonConnectSession) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode tonConnectSession#126556c6 as nil")
	}
	.PutID(TonConnectSessionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *TonConnectSession) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode tonConnectSession#126556c6 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode tonConnectSession#126556c6: field flags: %w", )
	}
	.PutLong(.ID)
	.PutString(.DappClientID)
	if .Flags.Has(3) {
		.PutString(.ClientID)
	}
	.PutBytes(.Nonce)
	if .Flags.Has(4) {
		if  := .Manifest.Encode();  != nil {
			return fmt.Errorf("unable to encode tonConnectSession#126556c6: field manifest: %w", )
		}
	}
	if .Flags.Has(5) {
		.PutInt(.ManifestError)
	}
	.PutInt(.Date)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *TonConnectSession) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode tonConnectSession#126556c6 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field flags: %w", )
		}
	}
	.Pending = .Flags.Has(0)
	.Closing = .Flags.Has(1)
	.Closed = .Flags.Has(2)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field dapp_client_id: %w", )
		}
		.DappClientID = 
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field client_id: %w", )
		}
		.ClientID = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field nonce: %w", )
		}
		.Nonce = 
	}
	if .Flags.Has(4) {
		if  := .Manifest.Decode();  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field manifest: %w", )
		}
	}
	if .Flags.Has(5) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field manifest_error: %w", )
		}
		.ManifestError = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode tonConnectSession#126556c6: field date: %w", )
		}
		.Date = 
	}
	return nil
}

// SetPending sets value of Pending conditional field.
func ( *TonConnectSession) ( bool) {
	if  {
		.Flags.Set(0)
		.Pending = true
	} else {
		.Flags.Unset(0)
		.Pending = false
	}
}

// GetPending returns value of Pending conditional field.
func ( *TonConnectSession) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetClosing sets value of Closing conditional field.
func ( *TonConnectSession) ( bool) {
	if  {
		.Flags.Set(1)
		.Closing = true
	} else {
		.Flags.Unset(1)
		.Closing = false
	}
}

// GetClosing returns value of Closing conditional field.
func ( *TonConnectSession) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetClosed sets value of Closed conditional field.
func ( *TonConnectSession) ( bool) {
	if  {
		.Flags.Set(2)
		.Closed = true
	} else {
		.Flags.Unset(2)
		.Closed = false
	}
}

// GetClosed returns value of Closed conditional field.
func ( *TonConnectSession) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetID returns value of ID field.
func ( *TonConnectSession) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// GetDappClientID returns value of DappClientID field.
func ( *TonConnectSession) () ( string) {
	if  == nil {
		return
	}
	return .DappClientID
}

// SetClientID sets value of ClientID conditional field.
func ( *TonConnectSession) ( string) {
	.Flags.Set(3)
	.ClientID = 
}

// GetClientID returns value of ClientID conditional field and
// boolean which is true if field was set.
func ( *TonConnectSession) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .ClientID, true
}

// GetNonce returns value of Nonce field.
func ( *TonConnectSession) () ( []byte) {
	if  == nil {
		return
	}
	return .Nonce
}

// SetManifest sets value of Manifest conditional field.
func ( *TonConnectSession) ( TonConnectManifest) {
	.Flags.Set(4)
	.Manifest = 
}

// GetManifest returns value of Manifest conditional field and
// boolean which is true if field was set.
func ( *TonConnectSession) () ( TonConnectManifest,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .Manifest, true
}

// SetManifestError sets value of ManifestError conditional field.
func ( *TonConnectSession) ( int) {
	.Flags.Set(5)
	.ManifestError = 
}

// GetManifestError returns value of ManifestError conditional field and
// boolean which is true if field was set.
func ( *TonConnectSession) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .ManifestError, true
}

// GetDate returns value of Date field.
func ( *TonConnectSession) () ( int) {
	if  == nil {
		return
	}
	return .Date
}