// Code generated by gotdgen, DO NOT EDIT.

package tdapi

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

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

// KeyboardButtonTypeText represents TL type `keyboardButtonTypeText#96519938`.
type KeyboardButtonTypeText struct {
}

// KeyboardButtonTypeTextTypeID is TL type id of KeyboardButtonTypeText.
const KeyboardButtonTypeTextTypeID = 0x96519938

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeText) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeText{}
)

func (k *KeyboardButtonTypeText) Zero() bool {
	if k == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeText) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeText",
		ID:   KeyboardButtonTypeTextTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeText) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeText#96519938 as nil")
	}
	b.PutID(KeyboardButtonTypeTextTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeText) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeText#96519938 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeText) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeText#96519938 to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeTextTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeText#96519938: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeText) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeText#96519938 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeText) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeText#96519938 as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeText")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeText) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeText#96519938 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeText"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeText#96519938: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// KeyboardButtonTypeRequestPhoneNumber represents TL type `keyboardButtonTypeRequestPhoneNumber#a4d9b7b9`.
type KeyboardButtonTypeRequestPhoneNumber struct {
}

// KeyboardButtonTypeRequestPhoneNumberTypeID is TL type id of KeyboardButtonTypeRequestPhoneNumber.
const KeyboardButtonTypeRequestPhoneNumberTypeID = 0xa4d9b7b9

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeRequestPhoneNumber) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeRequestPhoneNumber{}
)

func (k *KeyboardButtonTypeRequestPhoneNumber) Zero() bool {
	if k == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeRequestPhoneNumber) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeRequestPhoneNumber",
		ID:   KeyboardButtonTypeRequestPhoneNumberTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeRequestPhoneNumber) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9 as nil")
	}
	b.PutID(KeyboardButtonTypeRequestPhoneNumberTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeRequestPhoneNumber) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeRequestPhoneNumber) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9 to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeRequestPhoneNumberTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeRequestPhoneNumber) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeRequestPhoneNumber) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9 as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeRequestPhoneNumber")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeRequestPhoneNumber) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeRequestPhoneNumber"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestPhoneNumber#a4d9b7b9: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// KeyboardButtonTypeRequestLocation represents TL type `keyboardButtonTypeRequestLocation#f8828cfd`.
type KeyboardButtonTypeRequestLocation struct {
}

// KeyboardButtonTypeRequestLocationTypeID is TL type id of KeyboardButtonTypeRequestLocation.
const KeyboardButtonTypeRequestLocationTypeID = 0xf8828cfd

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeRequestLocation) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeRequestLocation{}
)

func (k *KeyboardButtonTypeRequestLocation) Zero() bool {
	if k == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeRequestLocation) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeRequestLocation",
		ID:   KeyboardButtonTypeRequestLocationTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeRequestLocation) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestLocation#f8828cfd as nil")
	}
	b.PutID(KeyboardButtonTypeRequestLocationTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeRequestLocation) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestLocation#f8828cfd as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeRequestLocation) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestLocation#f8828cfd to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeRequestLocationTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeRequestLocation#f8828cfd: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeRequestLocation) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestLocation#f8828cfd to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeRequestLocation) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestLocation#f8828cfd as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeRequestLocation")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeRequestLocation) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestLocation#f8828cfd to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeRequestLocation"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestLocation#f8828cfd: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// KeyboardButtonTypeRequestPoll represents TL type `keyboardButtonTypeRequestPoll#7164dcb8`.
type KeyboardButtonTypeRequestPoll struct {
	// If true, only regular polls must be allowed to create
	ForceRegular bool
	// If true, only polls in quiz mode must be allowed to create
	ForceQuiz bool
}

// KeyboardButtonTypeRequestPollTypeID is TL type id of KeyboardButtonTypeRequestPoll.
const KeyboardButtonTypeRequestPollTypeID = 0x7164dcb8

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeRequestPoll) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeRequestPoll{}
)

func (k *KeyboardButtonTypeRequestPoll) Zero() bool {
	if k == nil {
		return true
	}
	if !(k.ForceRegular == false) {
		return false
	}
	if !(k.ForceQuiz == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeRequestPoll) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeRequestPoll",
		ID:   KeyboardButtonTypeRequestPollTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ForceRegular",
			SchemaName: "force_regular",
		},
		{
			Name:       "ForceQuiz",
			SchemaName: "force_quiz",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeRequestPoll) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestPoll#7164dcb8 as nil")
	}
	b.PutID(KeyboardButtonTypeRequestPollTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeRequestPoll) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestPoll#7164dcb8 as nil")
	}
	b.PutBool(k.ForceRegular)
	b.PutBool(k.ForceQuiz)
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeRequestPoll) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestPoll#7164dcb8 to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeRequestPollTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeRequestPoll#7164dcb8: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeRequestPoll) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestPoll#7164dcb8 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestPoll#7164dcb8: field force_regular: %w", err)
		}
		k.ForceRegular = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestPoll#7164dcb8: field force_quiz: %w", err)
		}
		k.ForceQuiz = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeRequestPoll) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestPoll#7164dcb8 as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeRequestPoll")
	b.Comma()
	b.FieldStart("force_regular")
	b.PutBool(k.ForceRegular)
	b.Comma()
	b.FieldStart("force_quiz")
	b.PutBool(k.ForceQuiz)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeRequestPoll) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestPoll#7164dcb8 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeRequestPoll"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestPoll#7164dcb8: %w", err)
			}
		case "force_regular":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestPoll#7164dcb8: field force_regular: %w", err)
			}
			k.ForceRegular = value
		case "force_quiz":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestPoll#7164dcb8: field force_quiz: %w", err)
			}
			k.ForceQuiz = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetForceRegular returns value of ForceRegular field.
func (k *KeyboardButtonTypeRequestPoll) GetForceRegular() (value bool) {
	if k == nil {
		return
	}
	return k.ForceRegular
}

// GetForceQuiz returns value of ForceQuiz field.
func (k *KeyboardButtonTypeRequestPoll) GetForceQuiz() (value bool) {
	if k == nil {
		return
	}
	return k.ForceQuiz
}

// KeyboardButtonTypeRequestUsers represents TL type `keyboardButtonTypeRequestUsers#985c8bfd`.
type KeyboardButtonTypeRequestUsers struct {
	// Unique button identifier
	ID int32
	// True, if the shared users must or must not be bots
	RestrictUserIsBot bool
	// True, if the shared users must be bots; otherwise, the shared users must not be bots.
	// Ignored if restrict_user_is_bot is false
	UserIsBot bool
	// True, if the shared users must or must not be Telegram Premium users
	RestrictUserIsPremium bool
	// True, if the shared users must be Telegram Premium users; otherwise, the shared users
	// must not be Telegram Premium users. Ignored if restrict_user_is_premium is false
	UserIsPremium bool
	// The maximum number of users to share
	MaxQuantity int32
	// Pass true to request name of the users; bots only
	RequestName bool
	// Pass true to request username of the users; bots only
	RequestUsername bool
	// Pass true to request photo of the users; bots only
	RequestPhoto bool
}

// KeyboardButtonTypeRequestUsersTypeID is TL type id of KeyboardButtonTypeRequestUsers.
const KeyboardButtonTypeRequestUsersTypeID = 0x985c8bfd

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeRequestUsers) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeRequestUsers{}
)

func (k *KeyboardButtonTypeRequestUsers) Zero() bool {
	if k == nil {
		return true
	}
	if !(k.ID == 0) {
		return false
	}
	if !(k.RestrictUserIsBot == false) {
		return false
	}
	if !(k.UserIsBot == false) {
		return false
	}
	if !(k.RestrictUserIsPremium == false) {
		return false
	}
	if !(k.UserIsPremium == false) {
		return false
	}
	if !(k.MaxQuantity == 0) {
		return false
	}
	if !(k.RequestName == false) {
		return false
	}
	if !(k.RequestUsername == false) {
		return false
	}
	if !(k.RequestPhoto == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeRequestUsers) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeRequestUsers",
		ID:   KeyboardButtonTypeRequestUsersTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "RestrictUserIsBot",
			SchemaName: "restrict_user_is_bot",
		},
		{
			Name:       "UserIsBot",
			SchemaName: "user_is_bot",
		},
		{
			Name:       "RestrictUserIsPremium",
			SchemaName: "restrict_user_is_premium",
		},
		{
			Name:       "UserIsPremium",
			SchemaName: "user_is_premium",
		},
		{
			Name:       "MaxQuantity",
			SchemaName: "max_quantity",
		},
		{
			Name:       "RequestName",
			SchemaName: "request_name",
		},
		{
			Name:       "RequestUsername",
			SchemaName: "request_username",
		},
		{
			Name:       "RequestPhoto",
			SchemaName: "request_photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeRequestUsers) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestUsers#985c8bfd as nil")
	}
	b.PutID(KeyboardButtonTypeRequestUsersTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeRequestUsers) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestUsers#985c8bfd as nil")
	}
	b.PutInt32(k.ID)
	b.PutBool(k.RestrictUserIsBot)
	b.PutBool(k.UserIsBot)
	b.PutBool(k.RestrictUserIsPremium)
	b.PutBool(k.UserIsPremium)
	b.PutInt32(k.MaxQuantity)
	b.PutBool(k.RequestName)
	b.PutBool(k.RequestUsername)
	b.PutBool(k.RequestPhoto)
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeRequestUsers) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestUsers#985c8bfd to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeRequestUsersTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeRequestUsers) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestUsers#985c8bfd to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field id: %w", err)
		}
		k.ID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field restrict_user_is_bot: %w", err)
		}
		k.RestrictUserIsBot = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field user_is_bot: %w", err)
		}
		k.UserIsBot = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field restrict_user_is_premium: %w", err)
		}
		k.RestrictUserIsPremium = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field user_is_premium: %w", err)
		}
		k.UserIsPremium = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field max_quantity: %w", err)
		}
		k.MaxQuantity = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field request_name: %w", err)
		}
		k.RequestName = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field request_username: %w", err)
		}
		k.RequestUsername = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field request_photo: %w", err)
		}
		k.RequestPhoto = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeRequestUsers) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestUsers#985c8bfd as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeRequestUsers")
	b.Comma()
	b.FieldStart("id")
	b.PutInt32(k.ID)
	b.Comma()
	b.FieldStart("restrict_user_is_bot")
	b.PutBool(k.RestrictUserIsBot)
	b.Comma()
	b.FieldStart("user_is_bot")
	b.PutBool(k.UserIsBot)
	b.Comma()
	b.FieldStart("restrict_user_is_premium")
	b.PutBool(k.RestrictUserIsPremium)
	b.Comma()
	b.FieldStart("user_is_premium")
	b.PutBool(k.UserIsPremium)
	b.Comma()
	b.FieldStart("max_quantity")
	b.PutInt32(k.MaxQuantity)
	b.Comma()
	b.FieldStart("request_name")
	b.PutBool(k.RequestName)
	b.Comma()
	b.FieldStart("request_username")
	b.PutBool(k.RequestUsername)
	b.Comma()
	b.FieldStart("request_photo")
	b.PutBool(k.RequestPhoto)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeRequestUsers) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestUsers#985c8bfd to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeRequestUsers"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: %w", err)
			}
		case "id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field id: %w", err)
			}
			k.ID = value
		case "restrict_user_is_bot":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field restrict_user_is_bot: %w", err)
			}
			k.RestrictUserIsBot = value
		case "user_is_bot":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field user_is_bot: %w", err)
			}
			k.UserIsBot = value
		case "restrict_user_is_premium":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field restrict_user_is_premium: %w", err)
			}
			k.RestrictUserIsPremium = value
		case "user_is_premium":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field user_is_premium: %w", err)
			}
			k.UserIsPremium = value
		case "max_quantity":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field max_quantity: %w", err)
			}
			k.MaxQuantity = value
		case "request_name":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field request_name: %w", err)
			}
			k.RequestName = value
		case "request_username":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field request_username: %w", err)
			}
			k.RequestUsername = value
		case "request_photo":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestUsers#985c8bfd: field request_photo: %w", err)
			}
			k.RequestPhoto = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetID returns value of ID field.
func (k *KeyboardButtonTypeRequestUsers) GetID() (value int32) {
	if k == nil {
		return
	}
	return k.ID
}

// GetRestrictUserIsBot returns value of RestrictUserIsBot field.
func (k *KeyboardButtonTypeRequestUsers) GetRestrictUserIsBot() (value bool) {
	if k == nil {
		return
	}
	return k.RestrictUserIsBot
}

// GetUserIsBot returns value of UserIsBot field.
func (k *KeyboardButtonTypeRequestUsers) GetUserIsBot() (value bool) {
	if k == nil {
		return
	}
	return k.UserIsBot
}

// GetRestrictUserIsPremium returns value of RestrictUserIsPremium field.
func (k *KeyboardButtonTypeRequestUsers) GetRestrictUserIsPremium() (value bool) {
	if k == nil {
		return
	}
	return k.RestrictUserIsPremium
}

// GetUserIsPremium returns value of UserIsPremium field.
func (k *KeyboardButtonTypeRequestUsers) GetUserIsPremium() (value bool) {
	if k == nil {
		return
	}
	return k.UserIsPremium
}

// GetMaxQuantity returns value of MaxQuantity field.
func (k *KeyboardButtonTypeRequestUsers) GetMaxQuantity() (value int32) {
	if k == nil {
		return
	}
	return k.MaxQuantity
}

// GetRequestName returns value of RequestName field.
func (k *KeyboardButtonTypeRequestUsers) GetRequestName() (value bool) {
	if k == nil {
		return
	}
	return k.RequestName
}

// GetRequestUsername returns value of RequestUsername field.
func (k *KeyboardButtonTypeRequestUsers) GetRequestUsername() (value bool) {
	if k == nil {
		return
	}
	return k.RequestUsername
}

// GetRequestPhoto returns value of RequestPhoto field.
func (k *KeyboardButtonTypeRequestUsers) GetRequestPhoto() (value bool) {
	if k == nil {
		return
	}
	return k.RequestPhoto
}

// KeyboardButtonTypeRequestChat represents TL type `keyboardButtonTypeRequestChat#5a1224b5`.
type KeyboardButtonTypeRequestChat struct {
	// Unique button identifier
	ID int32
	// True, if the chat must be a channel; otherwise, a basic group or a supergroup chat is
	// shared
	ChatIsChannel bool
	// True, if the chat must or must not be a forum supergroup
	RestrictChatIsForum bool
	// True, if the chat must be a forum supergroup; otherwise, the chat must not be a forum
	// supergroup. Ignored if restrict_chat_is_forum is false
	ChatIsForum bool
	// True, if the chat must or must not have a username
	RestrictChatHasUsername bool
	// True, if the chat must have a username; otherwise, the chat must not have a username.
	// Ignored if restrict_chat_has_username is false
	ChatHasUsername bool
	// True, if the chat must be created by the current user
	ChatIsCreated bool
	// Expected user administrator rights in the chat; may be null if they aren't restricted
	UserAdministratorRights ChatAdministratorRights
	// Expected bot administrator rights in the chat; may be null if they aren't restricted
	BotAdministratorRights ChatAdministratorRights
	// True, if the bot must be a member of the chat; for basic group and supergroup chats
	// only
	BotIsMember bool
	// Pass true to request title of the chat; bots only
	RequestTitle bool
	// Pass true to request username of the chat; bots only
	RequestUsername bool
	// Pass true to request photo of the chat; bots only
	RequestPhoto bool
}

// KeyboardButtonTypeRequestChatTypeID is TL type id of KeyboardButtonTypeRequestChat.
const KeyboardButtonTypeRequestChatTypeID = 0x5a1224b5

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeRequestChat) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeRequestChat{}
)

func (k *KeyboardButtonTypeRequestChat) Zero() bool {
	if k == nil {
		return true
	}
	if !(k.ID == 0) {
		return false
	}
	if !(k.ChatIsChannel == false) {
		return false
	}
	if !(k.RestrictChatIsForum == false) {
		return false
	}
	if !(k.ChatIsForum == false) {
		return false
	}
	if !(k.RestrictChatHasUsername == false) {
		return false
	}
	if !(k.ChatHasUsername == false) {
		return false
	}
	if !(k.ChatIsCreated == false) {
		return false
	}
	if !(k.UserAdministratorRights.Zero()) {
		return false
	}
	if !(k.BotAdministratorRights.Zero()) {
		return false
	}
	if !(k.BotIsMember == false) {
		return false
	}
	if !(k.RequestTitle == false) {
		return false
	}
	if !(k.RequestUsername == false) {
		return false
	}
	if !(k.RequestPhoto == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeRequestChat) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeRequestChat",
		ID:   KeyboardButtonTypeRequestChatTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "ChatIsChannel",
			SchemaName: "chat_is_channel",
		},
		{
			Name:       "RestrictChatIsForum",
			SchemaName: "restrict_chat_is_forum",
		},
		{
			Name:       "ChatIsForum",
			SchemaName: "chat_is_forum",
		},
		{
			Name:       "RestrictChatHasUsername",
			SchemaName: "restrict_chat_has_username",
		},
		{
			Name:       "ChatHasUsername",
			SchemaName: "chat_has_username",
		},
		{
			Name:       "ChatIsCreated",
			SchemaName: "chat_is_created",
		},
		{
			Name:       "UserAdministratorRights",
			SchemaName: "user_administrator_rights",
		},
		{
			Name:       "BotAdministratorRights",
			SchemaName: "bot_administrator_rights",
		},
		{
			Name:       "BotIsMember",
			SchemaName: "bot_is_member",
		},
		{
			Name:       "RequestTitle",
			SchemaName: "request_title",
		},
		{
			Name:       "RequestUsername",
			SchemaName: "request_username",
		},
		{
			Name:       "RequestPhoto",
			SchemaName: "request_photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeRequestChat) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestChat#5a1224b5 as nil")
	}
	b.PutID(KeyboardButtonTypeRequestChatTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeRequestChat) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestChat#5a1224b5 as nil")
	}
	b.PutInt32(k.ID)
	b.PutBool(k.ChatIsChannel)
	b.PutBool(k.RestrictChatIsForum)
	b.PutBool(k.ChatIsForum)
	b.PutBool(k.RestrictChatHasUsername)
	b.PutBool(k.ChatHasUsername)
	b.PutBool(k.ChatIsCreated)
	if err := k.UserAdministratorRights.Encode(b); err != nil {
		return fmt.Errorf("unable to encode keyboardButtonTypeRequestChat#5a1224b5: field user_administrator_rights: %w", err)
	}
	if err := k.BotAdministratorRights.Encode(b); err != nil {
		return fmt.Errorf("unable to encode keyboardButtonTypeRequestChat#5a1224b5: field bot_administrator_rights: %w", err)
	}
	b.PutBool(k.BotIsMember)
	b.PutBool(k.RequestTitle)
	b.PutBool(k.RequestUsername)
	b.PutBool(k.RequestPhoto)
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeRequestChat) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestChat#5a1224b5 to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeRequestChatTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeRequestChat) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestChat#5a1224b5 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field id: %w", err)
		}
		k.ID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_is_channel: %w", err)
		}
		k.ChatIsChannel = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field restrict_chat_is_forum: %w", err)
		}
		k.RestrictChatIsForum = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_is_forum: %w", err)
		}
		k.ChatIsForum = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field restrict_chat_has_username: %w", err)
		}
		k.RestrictChatHasUsername = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_has_username: %w", err)
		}
		k.ChatHasUsername = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_is_created: %w", err)
		}
		k.ChatIsCreated = value
	}
	{
		if err := k.UserAdministratorRights.Decode(b); err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field user_administrator_rights: %w", err)
		}
	}
	{
		if err := k.BotAdministratorRights.Decode(b); err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field bot_administrator_rights: %w", err)
		}
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field bot_is_member: %w", err)
		}
		k.BotIsMember = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field request_title: %w", err)
		}
		k.RequestTitle = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field request_username: %w", err)
		}
		k.RequestUsername = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field request_photo: %w", err)
		}
		k.RequestPhoto = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeRequestChat) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeRequestChat#5a1224b5 as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeRequestChat")
	b.Comma()
	b.FieldStart("id")
	b.PutInt32(k.ID)
	b.Comma()
	b.FieldStart("chat_is_channel")
	b.PutBool(k.ChatIsChannel)
	b.Comma()
	b.FieldStart("restrict_chat_is_forum")
	b.PutBool(k.RestrictChatIsForum)
	b.Comma()
	b.FieldStart("chat_is_forum")
	b.PutBool(k.ChatIsForum)
	b.Comma()
	b.FieldStart("restrict_chat_has_username")
	b.PutBool(k.RestrictChatHasUsername)
	b.Comma()
	b.FieldStart("chat_has_username")
	b.PutBool(k.ChatHasUsername)
	b.Comma()
	b.FieldStart("chat_is_created")
	b.PutBool(k.ChatIsCreated)
	b.Comma()
	b.FieldStart("user_administrator_rights")
	if err := k.UserAdministratorRights.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode keyboardButtonTypeRequestChat#5a1224b5: field user_administrator_rights: %w", err)
	}
	b.Comma()
	b.FieldStart("bot_administrator_rights")
	if err := k.BotAdministratorRights.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode keyboardButtonTypeRequestChat#5a1224b5: field bot_administrator_rights: %w", err)
	}
	b.Comma()
	b.FieldStart("bot_is_member")
	b.PutBool(k.BotIsMember)
	b.Comma()
	b.FieldStart("request_title")
	b.PutBool(k.RequestTitle)
	b.Comma()
	b.FieldStart("request_username")
	b.PutBool(k.RequestUsername)
	b.Comma()
	b.FieldStart("request_photo")
	b.PutBool(k.RequestPhoto)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeRequestChat) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeRequestChat#5a1224b5 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeRequestChat"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: %w", err)
			}
		case "id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field id: %w", err)
			}
			k.ID = value
		case "chat_is_channel":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_is_channel: %w", err)
			}
			k.ChatIsChannel = value
		case "restrict_chat_is_forum":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field restrict_chat_is_forum: %w", err)
			}
			k.RestrictChatIsForum = value
		case "chat_is_forum":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_is_forum: %w", err)
			}
			k.ChatIsForum = value
		case "restrict_chat_has_username":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field restrict_chat_has_username: %w", err)
			}
			k.RestrictChatHasUsername = value
		case "chat_has_username":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_has_username: %w", err)
			}
			k.ChatHasUsername = value
		case "chat_is_created":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field chat_is_created: %w", err)
			}
			k.ChatIsCreated = value
		case "user_administrator_rights":
			if err := k.UserAdministratorRights.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field user_administrator_rights: %w", err)
			}
		case "bot_administrator_rights":
			if err := k.BotAdministratorRights.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field bot_administrator_rights: %w", err)
			}
		case "bot_is_member":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field bot_is_member: %w", err)
			}
			k.BotIsMember = value
		case "request_title":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field request_title: %w", err)
			}
			k.RequestTitle = value
		case "request_username":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field request_username: %w", err)
			}
			k.RequestUsername = value
		case "request_photo":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeRequestChat#5a1224b5: field request_photo: %w", err)
			}
			k.RequestPhoto = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetID returns value of ID field.
func (k *KeyboardButtonTypeRequestChat) GetID() (value int32) {
	if k == nil {
		return
	}
	return k.ID
}

// GetChatIsChannel returns value of ChatIsChannel field.
func (k *KeyboardButtonTypeRequestChat) GetChatIsChannel() (value bool) {
	if k == nil {
		return
	}
	return k.ChatIsChannel
}

// GetRestrictChatIsForum returns value of RestrictChatIsForum field.
func (k *KeyboardButtonTypeRequestChat) GetRestrictChatIsForum() (value bool) {
	if k == nil {
		return
	}
	return k.RestrictChatIsForum
}

// GetChatIsForum returns value of ChatIsForum field.
func (k *KeyboardButtonTypeRequestChat) GetChatIsForum() (value bool) {
	if k == nil {
		return
	}
	return k.ChatIsForum
}

// GetRestrictChatHasUsername returns value of RestrictChatHasUsername field.
func (k *KeyboardButtonTypeRequestChat) GetRestrictChatHasUsername() (value bool) {
	if k == nil {
		return
	}
	return k.RestrictChatHasUsername
}

// GetChatHasUsername returns value of ChatHasUsername field.
func (k *KeyboardButtonTypeRequestChat) GetChatHasUsername() (value bool) {
	if k == nil {
		return
	}
	return k.ChatHasUsername
}

// GetChatIsCreated returns value of ChatIsCreated field.
func (k *KeyboardButtonTypeRequestChat) GetChatIsCreated() (value bool) {
	if k == nil {
		return
	}
	return k.ChatIsCreated
}

// GetUserAdministratorRights returns value of UserAdministratorRights field.
func (k *KeyboardButtonTypeRequestChat) GetUserAdministratorRights() (value ChatAdministratorRights) {
	if k == nil {
		return
	}
	return k.UserAdministratorRights
}

// GetBotAdministratorRights returns value of BotAdministratorRights field.
func (k *KeyboardButtonTypeRequestChat) GetBotAdministratorRights() (value ChatAdministratorRights) {
	if k == nil {
		return
	}
	return k.BotAdministratorRights
}

// GetBotIsMember returns value of BotIsMember field.
func (k *KeyboardButtonTypeRequestChat) GetBotIsMember() (value bool) {
	if k == nil {
		return
	}
	return k.BotIsMember
}

// GetRequestTitle returns value of RequestTitle field.
func (k *KeyboardButtonTypeRequestChat) GetRequestTitle() (value bool) {
	if k == nil {
		return
	}
	return k.RequestTitle
}

// GetRequestUsername returns value of RequestUsername field.
func (k *KeyboardButtonTypeRequestChat) GetRequestUsername() (value bool) {
	if k == nil {
		return
	}
	return k.RequestUsername
}

// GetRequestPhoto returns value of RequestPhoto field.
func (k *KeyboardButtonTypeRequestChat) GetRequestPhoto() (value bool) {
	if k == nil {
		return
	}
	return k.RequestPhoto
}

// KeyboardButtonTypeWebApp represents TL type `keyboardButtonTypeWebApp#70c8ff62`.
type KeyboardButtonTypeWebApp struct {
	// An HTTP URL to pass to getWebAppUrl
	URL string
}

// KeyboardButtonTypeWebAppTypeID is TL type id of KeyboardButtonTypeWebApp.
const KeyboardButtonTypeWebAppTypeID = 0x70c8ff62

// construct implements constructor of KeyboardButtonTypeClass.
func (k KeyboardButtonTypeWebApp) construct() KeyboardButtonTypeClass { return &k }

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

	_ KeyboardButtonTypeClass = &KeyboardButtonTypeWebApp{}
)

func (k *KeyboardButtonTypeWebApp) Zero() bool {
	if k == nil {
		return true
	}
	if !(k.URL == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (k *KeyboardButtonTypeWebApp) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "keyboardButtonTypeWebApp",
		ID:   KeyboardButtonTypeWebAppTypeID,
	}
	if k == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (k *KeyboardButtonTypeWebApp) Encode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeWebApp#70c8ff62 as nil")
	}
	b.PutID(KeyboardButtonTypeWebAppTypeID)
	return k.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonTypeWebApp) EncodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeWebApp#70c8ff62 as nil")
	}
	b.PutString(k.URL)
	return nil
}

// Decode implements bin.Decoder.
func (k *KeyboardButtonTypeWebApp) Decode(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeWebApp#70c8ff62 to nil")
	}
	if err := b.ConsumeID(KeyboardButtonTypeWebAppTypeID); err != nil {
		return fmt.Errorf("unable to decode keyboardButtonTypeWebApp#70c8ff62: %w", err)
	}
	return k.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonTypeWebApp) DecodeBare(b *bin.Buffer) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeWebApp#70c8ff62 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode keyboardButtonTypeWebApp#70c8ff62: field url: %w", err)
		}
		k.URL = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (k *KeyboardButtonTypeWebApp) EncodeTDLibJSON(b tdjson.Encoder) error {
	if k == nil {
		return fmt.Errorf("can't encode keyboardButtonTypeWebApp#70c8ff62 as nil")
	}
	b.ObjStart()
	b.PutID("keyboardButtonTypeWebApp")
	b.Comma()
	b.FieldStart("url")
	b.PutString(k.URL)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (k *KeyboardButtonTypeWebApp) DecodeTDLibJSON(b tdjson.Decoder) error {
	if k == nil {
		return fmt.Errorf("can't decode keyboardButtonTypeWebApp#70c8ff62 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("keyboardButtonTypeWebApp"); err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeWebApp#70c8ff62: %w", err)
			}
		case "url":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode keyboardButtonTypeWebApp#70c8ff62: field url: %w", err)
			}
			k.URL = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetURL returns value of URL field.
func (k *KeyboardButtonTypeWebApp) GetURL() (value string) {
	if k == nil {
		return
	}
	return k.URL
}

// KeyboardButtonTypeClassName is schema name of KeyboardButtonTypeClass.
const KeyboardButtonTypeClassName = "KeyboardButtonType"

// KeyboardButtonTypeClass represents KeyboardButtonType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeKeyboardButtonType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.KeyboardButtonTypeText: // keyboardButtonTypeText#96519938
//	case *tdapi.KeyboardButtonTypeRequestPhoneNumber: // keyboardButtonTypeRequestPhoneNumber#a4d9b7b9
//	case *tdapi.KeyboardButtonTypeRequestLocation: // keyboardButtonTypeRequestLocation#f8828cfd
//	case *tdapi.KeyboardButtonTypeRequestPoll: // keyboardButtonTypeRequestPoll#7164dcb8
//	case *tdapi.KeyboardButtonTypeRequestUsers: // keyboardButtonTypeRequestUsers#985c8bfd
//	case *tdapi.KeyboardButtonTypeRequestChat: // keyboardButtonTypeRequestChat#5a1224b5
//	case *tdapi.KeyboardButtonTypeWebApp: // keyboardButtonTypeWebApp#70c8ff62
//	default: panic(v)
//	}
type KeyboardButtonTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() KeyboardButtonTypeClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeKeyboardButtonType implements binary de-serialization for KeyboardButtonTypeClass.
func DecodeKeyboardButtonType(buf *bin.Buffer) (KeyboardButtonTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case KeyboardButtonTypeTextTypeID:
		// Decoding keyboardButtonTypeText#96519938.
		v := KeyboardButtonTypeText{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case KeyboardButtonTypeRequestPhoneNumberTypeID:
		// Decoding keyboardButtonTypeRequestPhoneNumber#a4d9b7b9.
		v := KeyboardButtonTypeRequestPhoneNumber{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case KeyboardButtonTypeRequestLocationTypeID:
		// Decoding keyboardButtonTypeRequestLocation#f8828cfd.
		v := KeyboardButtonTypeRequestLocation{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case KeyboardButtonTypeRequestPollTypeID:
		// Decoding keyboardButtonTypeRequestPoll#7164dcb8.
		v := KeyboardButtonTypeRequestPoll{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case KeyboardButtonTypeRequestUsersTypeID:
		// Decoding keyboardButtonTypeRequestUsers#985c8bfd.
		v := KeyboardButtonTypeRequestUsers{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case KeyboardButtonTypeRequestChatTypeID:
		// Decoding keyboardButtonTypeRequestChat#5a1224b5.
		v := KeyboardButtonTypeRequestChat{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case KeyboardButtonTypeWebAppTypeID:
		// Decoding keyboardButtonTypeWebApp#70c8ff62.
		v := KeyboardButtonTypeWebApp{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONKeyboardButtonType implements binary de-serialization for KeyboardButtonTypeClass.
func DecodeTDLibJSONKeyboardButtonType(buf tdjson.Decoder) (KeyboardButtonTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "keyboardButtonTypeText":
		// Decoding keyboardButtonTypeText#96519938.
		v := KeyboardButtonTypeText{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case "keyboardButtonTypeRequestPhoneNumber":
		// Decoding keyboardButtonTypeRequestPhoneNumber#a4d9b7b9.
		v := KeyboardButtonTypeRequestPhoneNumber{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case "keyboardButtonTypeRequestLocation":
		// Decoding keyboardButtonTypeRequestLocation#f8828cfd.
		v := KeyboardButtonTypeRequestLocation{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case "keyboardButtonTypeRequestPoll":
		// Decoding keyboardButtonTypeRequestPoll#7164dcb8.
		v := KeyboardButtonTypeRequestPoll{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case "keyboardButtonTypeRequestUsers":
		// Decoding keyboardButtonTypeRequestUsers#985c8bfd.
		v := KeyboardButtonTypeRequestUsers{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case "keyboardButtonTypeRequestChat":
		// Decoding keyboardButtonTypeRequestChat#5a1224b5.
		v := KeyboardButtonTypeRequestChat{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	case "keyboardButtonTypeWebApp":
		// Decoding keyboardButtonTypeWebApp#70c8ff62.
		v := KeyboardButtonTypeWebApp{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode KeyboardButtonTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// KeyboardButtonType boxes the KeyboardButtonTypeClass providing a helper.
type KeyboardButtonTypeBox struct {
	KeyboardButtonType KeyboardButtonTypeClass
}

// Decode implements bin.Decoder for KeyboardButtonTypeBox.
func (b *KeyboardButtonTypeBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode KeyboardButtonTypeBox to nil")
	}
	v, err := DecodeKeyboardButtonType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.KeyboardButtonType = v
	return nil
}

// Encode implements bin.Encode for KeyboardButtonTypeBox.
func (b *KeyboardButtonTypeBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.KeyboardButtonType == nil {
		return fmt.Errorf("unable to encode KeyboardButtonTypeClass as nil")
	}
	return b.KeyboardButtonType.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for KeyboardButtonTypeBox.
func (b *KeyboardButtonTypeBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode KeyboardButtonTypeBox to nil")
	}
	v, err := DecodeTDLibJSONKeyboardButtonType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.KeyboardButtonType = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for KeyboardButtonTypeBox.
func (b *KeyboardButtonTypeBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.KeyboardButtonType == nil {
		return fmt.Errorf("unable to encode KeyboardButtonTypeClass as nil")
	}
	return b.KeyboardButtonType.EncodeTDLibJSON(buf)
}
