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

// Username represents TL type `username#b4073647`.
// Contains information about a username.
//
// See https://core.telegram.org/constructor/username for reference.
type Username struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the username is editable, meaning it wasn't bought on fragment¹.
	//
	// Links:
	//  1) https://fragment.com
	Editable bool
	// Whether the username is active.
	Active bool
	// The username.
	Username string
}

// UsernameTypeID is TL type id of Username.
const UsernameTypeID = 0xb4073647

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

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

	return true
}

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

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

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

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

// TypeInfo returns info about TL type.
func ( *Username) () tdp.Type {
	 := tdp.Type{
		Name: "username",
		ID:   UsernameTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Editable",
			SchemaName: "editable",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Active",
			SchemaName: "active",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Username",
			SchemaName: "username",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Username) () {
	if !(.Editable == false) {
		.Flags.Set(0)
	}
	if !(.Active == false) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *Username) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode username#b4073647 as nil")
	}
	.PutID(UsernameTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Username) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode username#b4073647 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode username#b4073647: field flags: %w", )
	}
	.PutString(.Username)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *Username) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode username#b4073647 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode username#b4073647: field flags: %w", )
		}
	}
	.Editable = .Flags.Has(0)
	.Active = .Flags.Has(1)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode username#b4073647: field username: %w", )
		}
		.Username = 
	}
	return nil
}

// SetEditable sets value of Editable conditional field.
func ( *Username) ( bool) {
	if  {
		.Flags.Set(0)
		.Editable = true
	} else {
		.Flags.Unset(0)
		.Editable = false
	}
}

// GetEditable returns value of Editable conditional field.
func ( *Username) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetActive sets value of Active conditional field.
func ( *Username) ( bool) {
	if  {
		.Flags.Set(1)
		.Active = true
	} else {
		.Flags.Unset(1)
		.Active = false
	}
}

// GetActive returns value of Active conditional field.
func ( *Username) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

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