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

// AccountToggleUsernameRequest represents TL type `account.toggleUsername#58d6b376`.
// Activate or deactivate a purchased fragment.comĀ¹ username associated to the currently
// logged-in user.
//
// Links:
//  1. https://fragment.com
//
// See https://core.telegram.org/method/account.toggleUsername for reference.
type AccountToggleUsernameRequest struct {
	// Username
	Username string
	// Whether to activate or deactivate it
	Active bool
}

// AccountToggleUsernameRequestTypeID is TL type id of AccountToggleUsernameRequest.
const AccountToggleUsernameRequestTypeID = 0x58d6b376

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

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

	return true
}

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

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

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

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

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

// Encode implements bin.Encoder.
func ( *AccountToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.toggleUsername#58d6b376 as nil")
	}
	.PutID(AccountToggleUsernameRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.toggleUsername#58d6b376 as nil")
	}
	.PutString(.Username)
	.PutBool(.Active)
	return nil
}

// Decode implements bin.Decoder.
func ( *AccountToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.toggleUsername#58d6b376 to nil")
	}
	if  := .ConsumeID(AccountToggleUsernameRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode account.toggleUsername#58d6b376: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AccountToggleUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.toggleUsername#58d6b376 to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.toggleUsername#58d6b376: field username: %w", )
		}
		.Username = 
	}
	{
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode account.toggleUsername#58d6b376: field active: %w", )
		}
		.Active = 
	}
	return nil
}

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

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

// AccountToggleUsername invokes method account.toggleUsername#58d6b376 returning error if any.
// Activate or deactivate a purchased fragment.comĀ¹ username associated to the currently
// logged-in user.
//
// Links:
//  1. https://fragment.com
//
// Possible errors:
//
//	400 USERNAMES_ACTIVE_TOO_MUCH: The maximum number of active usernames was reached.
//	400 USERNAME_INVALID: The provided username is not valid.
//
// See https://core.telegram.org/method/account.toggleUsername for reference.
func ( *Client) ( context.Context,  *AccountToggleUsernameRequest) (bool, error) {
	var  BoolBox

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