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

// ChannelsUpdateUsernameRequest represents TL type `channels.updateUsername#3514b3de`.
// Change or remove the username of a supergroup/channel
//
// See https://core.telegram.org/method/channels.updateUsername for reference.
type ChannelsUpdateUsernameRequest struct {
	// Channel
	Channel InputChannelClass
	// New username, pass an empty string to remove the username
	Username string
}

// ChannelsUpdateUsernameRequestTypeID is TL type id of ChannelsUpdateUsernameRequest.
const ChannelsUpdateUsernameRequestTypeID = 0x3514b3de

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

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

	return true
}

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

// FillFrom fills ChannelsUpdateUsernameRequest from given interface.
func ( *ChannelsUpdateUsernameRequest) ( interface {
	() ( InputChannelClass)
	() ( string)
}) {
	.Channel = .()
	.Username = .()
}

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

// TypeName returns name of type in TL schema.
func (*ChannelsUpdateUsernameRequest) () string {
	return "channels.updateUsername"
}

// TypeInfo returns info about TL type.
func ( *ChannelsUpdateUsernameRequest) () tdp.Type {
	 := tdp.Type{
		Name: "channels.updateUsername",
		ID:   ChannelsUpdateUsernameRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "Username",
			SchemaName: "username",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ChannelsUpdateUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.updateUsername#3514b3de as nil")
	}
	.PutID(ChannelsUpdateUsernameRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChannelsUpdateUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.updateUsername#3514b3de as nil")
	}
	if .Channel == nil {
		return fmt.Errorf("unable to encode channels.updateUsername#3514b3de: field channel is nil")
	}
	if  := .Channel.Encode();  != nil {
		return fmt.Errorf("unable to encode channels.updateUsername#3514b3de: field channel: %w", )
	}
	.PutString(.Username)
	return nil
}

// Decode implements bin.Decoder.
func ( *ChannelsUpdateUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.updateUsername#3514b3de to nil")
	}
	if  := .ConsumeID(ChannelsUpdateUsernameRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode channels.updateUsername#3514b3de: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChannelsUpdateUsernameRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.updateUsername#3514b3de to nil")
	}
	{
		,  := DecodeInputChannel()
		if  != nil {
			return fmt.Errorf("unable to decode channels.updateUsername#3514b3de: field channel: %w", )
		}
		.Channel = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode channels.updateUsername#3514b3de: field username: %w", )
		}
		.Username = 
	}
	return nil
}

// GetChannel returns value of Channel field.
func ( *ChannelsUpdateUsernameRequest) () ( InputChannelClass) {
	if  == nil {
		return
	}
	return .Channel
}

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

// GetChannelAsNotEmpty returns mapped value of Channel field.
func ( *ChannelsUpdateUsernameRequest) () (NotEmptyInputChannel, bool) {
	return .Channel.AsNotEmpty()
}

// ChannelsUpdateUsername invokes method channels.updateUsername#3514b3de returning error if any.
// Change or remove the username of a supergroup/channel
//
// Possible errors:
//
//	400 CHANNELS_ADMIN_PUBLIC_TOO_MUCH: You're admin of too many public channels, make some channels private to change the username of this channel.
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	403 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	400 CHAT_NOT_MODIFIED: No changes were made to chat information because the new information you passed is identical to the current information.
//	403 CHAT_WRITE_FORBIDDEN: You can't write in this chat.
//	400 USERNAME_INVALID: The provided username is not valid.
//	400 USERNAME_NOT_MODIFIED: The username was not modified.
//	400 USERNAME_OCCUPIED: The provided username is already occupied.
//	400 USERNAME_PURCHASE_AVAILABLE: The specified username can be purchased on https://fragment.com.
//
// See https://core.telegram.org/method/channels.updateUsername for reference.
func ( *Client) ( context.Context,  *ChannelsUpdateUsernameRequest) (bool, error) {
	var  BoolBox

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