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

// BotsToggleUsernameRequest represents TL type `bots.toggleUsername#53ca973`.
// Activate or deactivate a purchased fragment.comĀ¹ username associated to a bot we own.
//
// Links:
//  1. https://fragment.com
//
// See https://core.telegram.org/method/bots.toggleUsername for reference.
type BotsToggleUsernameRequest struct {
	// The bot
	Bot InputUserClass
	// Username
	Username string
	// Whether to activate or deactivate it
	Active bool
}

// BotsToggleUsernameRequestTypeID is TL type id of BotsToggleUsernameRequest.
const BotsToggleUsernameRequestTypeID = 0x53ca973

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

func ( *BotsToggleUsernameRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Bot == nil) {
		return false
	}
	if !(.Username == "") {
		return false
	}
	if !(.Active == false) {
		return false
	}

	return true
}

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

// FillFrom fills BotsToggleUsernameRequest from given interface.
func ( *BotsToggleUsernameRequest) ( interface {
	() ( InputUserClass)
	() ( string)
	() ( bool)
}) {
	.Bot = .()
	.Username = .()
	.Active = .()
}

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

// TypeName returns name of type in TL schema.
func (*BotsToggleUsernameRequest) () string {
	return "bots.toggleUsername"
}

// TypeInfo returns info about TL type.
func ( *BotsToggleUsernameRequest) () tdp.Type {
	 := tdp.Type{
		Name: "bots.toggleUsername",
		ID:   BotsToggleUsernameRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "Username",
			SchemaName: "username",
		},
		{
			Name:       "Active",
			SchemaName: "active",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *BotsToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode bots.toggleUsername#53ca973 as nil")
	}
	.PutID(BotsToggleUsernameRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *BotsToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode bots.toggleUsername#53ca973 as nil")
	}
	if .Bot == nil {
		return fmt.Errorf("unable to encode bots.toggleUsername#53ca973: field bot is nil")
	}
	if  := .Bot.Encode();  != nil {
		return fmt.Errorf("unable to encode bots.toggleUsername#53ca973: field bot: %w", )
	}
	.PutString(.Username)
	.PutBool(.Active)
	return nil
}

// Decode implements bin.Decoder.
func ( *BotsToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode bots.toggleUsername#53ca973 to nil")
	}
	if  := .ConsumeID(BotsToggleUsernameRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode bots.toggleUsername#53ca973: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *BotsToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode bots.toggleUsername#53ca973 to nil")
	}
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode bots.toggleUsername#53ca973: field bot: %w", )
		}
		.Bot = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode bots.toggleUsername#53ca973: field username: %w", )
		}
		.Username = 
	}
	{
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode bots.toggleUsername#53ca973: field active: %w", )
		}
		.Active = 
	}
	return nil
}

// GetBot returns value of Bot field.
func ( *BotsToggleUsernameRequest) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .Bot
}

// GetUsername returns value of Username field.
func ( *BotsToggleUsernameRequest) () ( string) {
	if  == nil {
		return
	}
	return .Username
}

// GetActive returns value of Active field.
func ( *BotsToggleUsernameRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Active
}

// BotsToggleUsername invokes method bots.toggleUsername#53ca973 returning error if any.
// Activate or deactivate a purchased fragment.comĀ¹ username associated to a bot we own.
//
// Links:
//  1. https://fragment.com
//
// Possible errors:
//
//	400 BOT_INVALID: This is not a valid bot.
//
// See https://core.telegram.org/method/bots.toggleUsername for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *BotsToggleUsernameRequest) (bool, error) {
	var  BoolBox

	if  := .rpc.Invoke(, , &);  != nil {
		return false, 
	}
	,  := .Bool.(*BoolTrue)
	return , nil
}