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

// BotBusinessConnection represents TL type `botBusinessConnection#8f34b2f5`.
// Contains info about a bot business connection¹.
//
// Links:
//  1. https://core.telegram.org/api/bots/connected-business-bots
//
// See https://core.telegram.org/constructor/botBusinessConnection for reference.
type BotBusinessConnection struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this business connection is currently disabled
	Disabled bool
	// Business connection ID, used to identify messages coming from the connection and to
	// reply to them as specified here »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/bots/connected-business-bots
	ConnectionID string
	// ID of the user that the bot is connected to via this connection.
	UserID int64
	// ID of the datacenter where to send queries wrapped in a invokeWithBusinessConnection¹
	// as specified here »².
	//
	// Links:
	//  1) https://core.telegram.org/method/invokeWithBusinessConnection
	//  2) https://core.telegram.org/api/bots/connected-business-bots
	DCID int
	// When was the connection created.
	Date int
	// Business bot rights.
	//
	// Use SetRights and GetRights helpers.
	Rights BusinessBotRights
}

// BotBusinessConnectionTypeID is TL type id of BotBusinessConnection.
const BotBusinessConnectionTypeID = 0x8f34b2f5

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

func ( *BotBusinessConnection) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Disabled == false) {
		return false
	}
	if !(.ConnectionID == "") {
		return false
	}
	if !(.UserID == 0) {
		return false
	}
	if !(.DCID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Rights.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills BotBusinessConnection from given interface.
func ( *BotBusinessConnection) ( interface {
	() ( bool)
	() ( string)
	() ( int64)
	() ( int)
	() ( int)
	() ( BusinessBotRights,  bool)
}) {
	.Disabled = .()
	.ConnectionID = .()
	.UserID = .()
	.DCID = .()
	.Date = .()
	if ,  := .();  {
		.Rights = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *BotBusinessConnection) () tdp.Type {
	 := tdp.Type{
		Name: "botBusinessConnection",
		ID:   BotBusinessConnectionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Disabled",
			SchemaName: "disabled",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ConnectionID",
			SchemaName: "connection_id",
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Rights",
			SchemaName: "rights",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *BotBusinessConnection) () {
	if !(.Disabled == false) {
		.Flags.Set(1)
	}
	if !(.Rights.Zero()) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *BotBusinessConnection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode botBusinessConnection#8f34b2f5 as nil")
	}
	.PutID(BotBusinessConnectionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *BotBusinessConnection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode botBusinessConnection#8f34b2f5 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode botBusinessConnection#8f34b2f5: field flags: %w", )
	}
	.PutString(.ConnectionID)
	.PutLong(.UserID)
	.PutInt(.DCID)
	.PutInt(.Date)
	if .Flags.Has(2) {
		if  := .Rights.Encode();  != nil {
			return fmt.Errorf("unable to encode botBusinessConnection#8f34b2f5: field rights: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *BotBusinessConnection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode botBusinessConnection#8f34b2f5 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode botBusinessConnection#8f34b2f5: field flags: %w", )
		}
	}
	.Disabled = .Flags.Has(1)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode botBusinessConnection#8f34b2f5: field connection_id: %w", )
		}
		.ConnectionID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode botBusinessConnection#8f34b2f5: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode botBusinessConnection#8f34b2f5: field dc_id: %w", )
		}
		.DCID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode botBusinessConnection#8f34b2f5: field date: %w", )
		}
		.Date = 
	}
	if .Flags.Has(2) {
		if  := .Rights.Decode();  != nil {
			return fmt.Errorf("unable to decode botBusinessConnection#8f34b2f5: field rights: %w", )
		}
	}
	return nil
}

// SetDisabled sets value of Disabled conditional field.
func ( *BotBusinessConnection) ( bool) {
	if  {
		.Flags.Set(1)
		.Disabled = true
	} else {
		.Flags.Unset(1)
		.Disabled = false
	}
}

// GetDisabled returns value of Disabled conditional field.
func ( *BotBusinessConnection) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetConnectionID returns value of ConnectionID field.
func ( *BotBusinessConnection) () ( string) {
	if  == nil {
		return
	}
	return .ConnectionID
}

// GetUserID returns value of UserID field.
func ( *BotBusinessConnection) () ( int64) {
	if  == nil {
		return
	}
	return .UserID
}

// GetDCID returns value of DCID field.
func ( *BotBusinessConnection) () ( int) {
	if  == nil {
		return
	}
	return .DCID
}

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

// SetRights sets value of Rights conditional field.
func ( *BotBusinessConnection) ( BusinessBotRights) {
	.Flags.Set(2)
	.Rights = 
}

// GetRights returns value of Rights conditional field and
// boolean which is true if field was set.
func ( *BotBusinessConnection) () ( BusinessBotRights,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Rights, true
}