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

// AuthenticationCodeTypeTelegramMessage represents TL type `authenticationCodeTypeTelegramMessage#7bf49b2a`.
type AuthenticationCodeTypeTelegramMessage struct {
	// Length of the code
	Length int32
}

// AuthenticationCodeTypeTelegramMessageTypeID is TL type id of AuthenticationCodeTypeTelegramMessage.
const AuthenticationCodeTypeTelegramMessageTypeID = 0x7bf49b2a

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeTelegramMessage) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeTelegramMessage{}
)

func (a *AuthenticationCodeTypeTelegramMessage) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeTelegramMessage) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeTelegramMessage",
		ID:   AuthenticationCodeTypeTelegramMessageTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeTelegramMessage) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeTelegramMessage#7bf49b2a as nil")
	}
	b.PutID(AuthenticationCodeTypeTelegramMessageTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeTelegramMessage) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeTelegramMessage#7bf49b2a as nil")
	}
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeTelegramMessage) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeTelegramMessage#7bf49b2a to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeTelegramMessageTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeTelegramMessage#7bf49b2a: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeTelegramMessage) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeTelegramMessage#7bf49b2a to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeTelegramMessage#7bf49b2a: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeTelegramMessage) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeTelegramMessage#7bf49b2a as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeTelegramMessage")
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeTelegramMessage) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeTelegramMessage#7bf49b2a to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeTelegramMessage"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeTelegramMessage#7bf49b2a: %w", err)
			}
		case "length":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeTelegramMessage#7bf49b2a: field length: %w", err)
			}
			a.Length = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeTelegramMessage) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeSMS represents TL type `authenticationCodeTypeSms#3960e288`.
type AuthenticationCodeTypeSMS struct {
	// Length of the code
	Length int32
}

// AuthenticationCodeTypeSMSTypeID is TL type id of AuthenticationCodeTypeSMS.
const AuthenticationCodeTypeSMSTypeID = 0x3960e288

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeSMS) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeSMS{}
)

func (a *AuthenticationCodeTypeSMS) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeSMS) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeSms",
		ID:   AuthenticationCodeTypeSMSTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeSMS) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSms#3960e288 as nil")
	}
	b.PutID(AuthenticationCodeTypeSMSTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeSMS) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSms#3960e288 as nil")
	}
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeSMS) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSms#3960e288 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeSMSTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeSms#3960e288: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeSMS) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSms#3960e288 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeSms#3960e288: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeSMS) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSms#3960e288 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeSms")
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeSMS) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSms#3960e288 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeSms"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeSms#3960e288: %w", err)
			}
		case "length":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeSms#3960e288: field length: %w", err)
			}
			a.Length = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeSMS) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeSMSWord represents TL type `authenticationCodeTypeSmsWord#a6063c63`.
type AuthenticationCodeTypeSMSWord struct {
	// The first letters of the word if known
	FirstLetter string
}

// AuthenticationCodeTypeSMSWordTypeID is TL type id of AuthenticationCodeTypeSMSWord.
const AuthenticationCodeTypeSMSWordTypeID = 0xa6063c63

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeSMSWord) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeSMSWord{}
)

func (a *AuthenticationCodeTypeSMSWord) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.FirstLetter == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeSMSWord) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeSmsWord",
		ID:   AuthenticationCodeTypeSMSWordTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "FirstLetter",
			SchemaName: "first_letter",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeSMSWord) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSmsWord#a6063c63 as nil")
	}
	b.PutID(AuthenticationCodeTypeSMSWordTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeSMSWord) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSmsWord#a6063c63 as nil")
	}
	b.PutString(a.FirstLetter)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeSMSWord) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSmsWord#a6063c63 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeSMSWordTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeSmsWord#a6063c63: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeSMSWord) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSmsWord#a6063c63 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeSmsWord#a6063c63: field first_letter: %w", err)
		}
		a.FirstLetter = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeSMSWord) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSmsWord#a6063c63 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeSmsWord")
	b.Comma()
	b.FieldStart("first_letter")
	b.PutString(a.FirstLetter)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeSMSWord) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSmsWord#a6063c63 to nil")
	}

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

// GetFirstLetter returns value of FirstLetter field.
func (a *AuthenticationCodeTypeSMSWord) GetFirstLetter() (value string) {
	if a == nil {
		return
	}
	return a.FirstLetter
}

// AuthenticationCodeTypeSMSPhrase represents TL type `authenticationCodeTypeSmsPhrase#2ebc8cd1`.
type AuthenticationCodeTypeSMSPhrase struct {
	// The first word of the phrase if known
	FirstWord string
}

// AuthenticationCodeTypeSMSPhraseTypeID is TL type id of AuthenticationCodeTypeSMSPhrase.
const AuthenticationCodeTypeSMSPhraseTypeID = 0x2ebc8cd1

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeSMSPhrase) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeSMSPhrase{}
)

func (a *AuthenticationCodeTypeSMSPhrase) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.FirstWord == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeSMSPhrase) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeSmsPhrase",
		ID:   AuthenticationCodeTypeSMSPhraseTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "FirstWord",
			SchemaName: "first_word",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeSMSPhrase) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSmsPhrase#2ebc8cd1 as nil")
	}
	b.PutID(AuthenticationCodeTypeSMSPhraseTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeSMSPhrase) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSmsPhrase#2ebc8cd1 as nil")
	}
	b.PutString(a.FirstWord)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeSMSPhrase) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSmsPhrase#2ebc8cd1 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeSMSPhraseTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeSmsPhrase#2ebc8cd1: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeSMSPhrase) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSmsPhrase#2ebc8cd1 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeSmsPhrase#2ebc8cd1: field first_word: %w", err)
		}
		a.FirstWord = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeSMSPhrase) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeSmsPhrase#2ebc8cd1 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeSmsPhrase")
	b.Comma()
	b.FieldStart("first_word")
	b.PutString(a.FirstWord)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeSMSPhrase) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeSmsPhrase#2ebc8cd1 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeSmsPhrase"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeSmsPhrase#2ebc8cd1: %w", err)
			}
		case "first_word":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeSmsPhrase#2ebc8cd1: field first_word: %w", err)
			}
			a.FirstWord = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetFirstWord returns value of FirstWord field.
func (a *AuthenticationCodeTypeSMSPhrase) GetFirstWord() (value string) {
	if a == nil {
		return
	}
	return a.FirstWord
}

// AuthenticationCodeTypeCall represents TL type `authenticationCodeTypeCall#61876c67`.
type AuthenticationCodeTypeCall struct {
	// Length of the code
	Length int32
}

// AuthenticationCodeTypeCallTypeID is TL type id of AuthenticationCodeTypeCall.
const AuthenticationCodeTypeCallTypeID = 0x61876c67

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeCall) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeCall{}
)

func (a *AuthenticationCodeTypeCall) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeCall",
		ID:   AuthenticationCodeTypeCallTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeCall) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeCall#61876c67 as nil")
	}
	b.PutID(AuthenticationCodeTypeCallTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeCall) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeCall#61876c67 as nil")
	}
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeCall) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeCall#61876c67 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeCallTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeCall#61876c67: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeCall) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeCall#61876c67 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeCall#61876c67: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeCall) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeCall#61876c67 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeCall")
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeCall) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeCall#61876c67 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeCall"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeCall#61876c67: %w", err)
			}
		case "length":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeCall#61876c67: field length: %w", err)
			}
			a.Length = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeCall) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeFlashCall represents TL type `authenticationCodeTypeFlashCall#533379a2`.
type AuthenticationCodeTypeFlashCall struct {
	// Pattern of the phone number from which the call will be made
	Pattern string
}

// AuthenticationCodeTypeFlashCallTypeID is TL type id of AuthenticationCodeTypeFlashCall.
const AuthenticationCodeTypeFlashCallTypeID = 0x533379a2

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeFlashCall) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeFlashCall{}
)

func (a *AuthenticationCodeTypeFlashCall) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Pattern == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeFlashCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeFlashCall",
		ID:   AuthenticationCodeTypeFlashCallTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Pattern",
			SchemaName: "pattern",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeFlashCall) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFlashCall#533379a2 as nil")
	}
	b.PutID(AuthenticationCodeTypeFlashCallTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeFlashCall) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFlashCall#533379a2 as nil")
	}
	b.PutString(a.Pattern)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeFlashCall) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFlashCall#533379a2 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeFlashCallTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeFlashCall#533379a2: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeFlashCall) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFlashCall#533379a2 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFlashCall#533379a2: field pattern: %w", err)
		}
		a.Pattern = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeFlashCall) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFlashCall#533379a2 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeFlashCall")
	b.Comma()
	b.FieldStart("pattern")
	b.PutString(a.Pattern)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeFlashCall) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFlashCall#533379a2 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeFlashCall"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFlashCall#533379a2: %w", err)
			}
		case "pattern":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFlashCall#533379a2: field pattern: %w", err)
			}
			a.Pattern = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPattern returns value of Pattern field.
func (a *AuthenticationCodeTypeFlashCall) GetPattern() (value string) {
	if a == nil {
		return
	}
	return a.Pattern
}

// AuthenticationCodeTypeMissedCall represents TL type `authenticationCodeTypeMissedCall#29bb0a87`.
type AuthenticationCodeTypeMissedCall struct {
	// Prefix of the phone number from which the call will be made
	PhoneNumberPrefix string
	// Number of digits in the code, excluding the prefix
	Length int32
}

// AuthenticationCodeTypeMissedCallTypeID is TL type id of AuthenticationCodeTypeMissedCall.
const AuthenticationCodeTypeMissedCallTypeID = 0x29bb0a87

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeMissedCall) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeMissedCall{}
)

func (a *AuthenticationCodeTypeMissedCall) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.PhoneNumberPrefix == "") {
		return false
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeMissedCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeMissedCall",
		ID:   AuthenticationCodeTypeMissedCallTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "PhoneNumberPrefix",
			SchemaName: "phone_number_prefix",
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeMissedCall) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeMissedCall#29bb0a87 as nil")
	}
	b.PutID(AuthenticationCodeTypeMissedCallTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeMissedCall) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeMissedCall#29bb0a87 as nil")
	}
	b.PutString(a.PhoneNumberPrefix)
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeMissedCall) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeMissedCall#29bb0a87 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeMissedCallTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeMissedCall#29bb0a87: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeMissedCall) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeMissedCall#29bb0a87 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeMissedCall#29bb0a87: field phone_number_prefix: %w", err)
		}
		a.PhoneNumberPrefix = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeMissedCall#29bb0a87: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeMissedCall) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeMissedCall#29bb0a87 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeMissedCall")
	b.Comma()
	b.FieldStart("phone_number_prefix")
	b.PutString(a.PhoneNumberPrefix)
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeMissedCall) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeMissedCall#29bb0a87 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeMissedCall"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeMissedCall#29bb0a87: %w", err)
			}
		case "phone_number_prefix":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeMissedCall#29bb0a87: field phone_number_prefix: %w", err)
			}
			a.PhoneNumberPrefix = value
		case "length":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeMissedCall#29bb0a87: field length: %w", err)
			}
			a.Length = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoneNumberPrefix returns value of PhoneNumberPrefix field.
func (a *AuthenticationCodeTypeMissedCall) GetPhoneNumberPrefix() (value string) {
	if a == nil {
		return
	}
	return a.PhoneNumberPrefix
}

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeMissedCall) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeFragment represents TL type `authenticationCodeTypeFragment#810f74cd`.
type AuthenticationCodeTypeFragment struct {
	// URL to open to receive the code
	URL string
	// Length of the code
	Length int32
}

// AuthenticationCodeTypeFragmentTypeID is TL type id of AuthenticationCodeTypeFragment.
const AuthenticationCodeTypeFragmentTypeID = 0x810f74cd

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeFragment) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeFragment{}
)

func (a *AuthenticationCodeTypeFragment) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.URL == "") {
		return false
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeFragment) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeFragment",
		ID:   AuthenticationCodeTypeFragmentTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeFragment) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFragment#810f74cd as nil")
	}
	b.PutID(AuthenticationCodeTypeFragmentTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeFragment) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFragment#810f74cd as nil")
	}
	b.PutString(a.URL)
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeFragment) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFragment#810f74cd to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeFragmentTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeFragment#810f74cd: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeFragment) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFragment#810f74cd to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFragment#810f74cd: field url: %w", err)
		}
		a.URL = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFragment#810f74cd: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeFragment) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFragment#810f74cd as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeFragment")
	b.Comma()
	b.FieldStart("url")
	b.PutString(a.URL)
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeFragment) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFragment#810f74cd to nil")
	}

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

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

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeFragment) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeFirebaseAndroid represents TL type `authenticationCodeTypeFirebaseAndroid#6f9bb51e`.
type AuthenticationCodeTypeFirebaseAndroid struct {
	// Parameters to be used for device verification
	DeviceVerificationParameters FirebaseDeviceVerificationParametersClass
	// Length of the code
	Length int32
}

// AuthenticationCodeTypeFirebaseAndroidTypeID is TL type id of AuthenticationCodeTypeFirebaseAndroid.
const AuthenticationCodeTypeFirebaseAndroidTypeID = 0x6f9bb51e

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeFirebaseAndroid) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeFirebaseAndroid{}
)

func (a *AuthenticationCodeTypeFirebaseAndroid) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.DeviceVerificationParameters == nil) {
		return false
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeFirebaseAndroid) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeFirebaseAndroid",
		ID:   AuthenticationCodeTypeFirebaseAndroidTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DeviceVerificationParameters",
			SchemaName: "device_verification_parameters",
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeFirebaseAndroid) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFirebaseAndroid#6f9bb51e as nil")
	}
	b.PutID(AuthenticationCodeTypeFirebaseAndroidTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeFirebaseAndroid) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFirebaseAndroid#6f9bb51e as nil")
	}
	if a.DeviceVerificationParameters == nil {
		return fmt.Errorf("unable to encode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field device_verification_parameters is nil")
	}
	if err := a.DeviceVerificationParameters.Encode(b); err != nil {
		return fmt.Errorf("unable to encode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field device_verification_parameters: %w", err)
	}
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeFirebaseAndroid) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFirebaseAndroid#6f9bb51e to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeFirebaseAndroidTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseAndroid#6f9bb51e: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeFirebaseAndroid) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFirebaseAndroid#6f9bb51e to nil")
	}
	{
		value, err := DecodeFirebaseDeviceVerificationParameters(b)
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field device_verification_parameters: %w", err)
		}
		a.DeviceVerificationParameters = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeFirebaseAndroid) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFirebaseAndroid#6f9bb51e as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeFirebaseAndroid")
	b.Comma()
	b.FieldStart("device_verification_parameters")
	if a.DeviceVerificationParameters == nil {
		return fmt.Errorf("unable to encode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field device_verification_parameters is nil")
	}
	if err := a.DeviceVerificationParameters.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field device_verification_parameters: %w", err)
	}
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeFirebaseAndroid) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFirebaseAndroid#6f9bb51e to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeFirebaseAndroid"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseAndroid#6f9bb51e: %w", err)
			}
		case "device_verification_parameters":
			value, err := DecodeTDLibJSONFirebaseDeviceVerificationParameters(b)
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field device_verification_parameters: %w", err)
			}
			a.DeviceVerificationParameters = value
		case "length":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseAndroid#6f9bb51e: field length: %w", err)
			}
			a.Length = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetDeviceVerificationParameters returns value of DeviceVerificationParameters field.
func (a *AuthenticationCodeTypeFirebaseAndroid) GetDeviceVerificationParameters() (value FirebaseDeviceVerificationParametersClass) {
	if a == nil {
		return
	}
	return a.DeviceVerificationParameters
}

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeFirebaseAndroid) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeFirebaseIos represents TL type `authenticationCodeTypeFirebaseIos#ff55aa93`.
type AuthenticationCodeTypeFirebaseIos struct {
	// Receipt of successful application token validation to compare with receipt from push
	// notification
	Receipt string
	// Time after the next authentication method is expected to be used if verification push
	// notification isn't received, in seconds
	PushTimeout int32
	// Length of the code
	Length int32
}

// AuthenticationCodeTypeFirebaseIosTypeID is TL type id of AuthenticationCodeTypeFirebaseIos.
const AuthenticationCodeTypeFirebaseIosTypeID = 0xff55aa93

// construct implements constructor of AuthenticationCodeTypeClass.
func (a AuthenticationCodeTypeFirebaseIos) construct() AuthenticationCodeTypeClass { return &a }

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

	_ AuthenticationCodeTypeClass = &AuthenticationCodeTypeFirebaseIos{}
)

func (a *AuthenticationCodeTypeFirebaseIos) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Receipt == "") {
		return false
	}
	if !(a.PushTimeout == 0) {
		return false
	}
	if !(a.Length == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AuthenticationCodeTypeFirebaseIos) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "authenticationCodeTypeFirebaseIos",
		ID:   AuthenticationCodeTypeFirebaseIosTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Receipt",
			SchemaName: "receipt",
		},
		{
			Name:       "PushTimeout",
			SchemaName: "push_timeout",
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AuthenticationCodeTypeFirebaseIos) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFirebaseIos#ff55aa93 as nil")
	}
	b.PutID(AuthenticationCodeTypeFirebaseIosTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AuthenticationCodeTypeFirebaseIos) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFirebaseIos#ff55aa93 as nil")
	}
	b.PutString(a.Receipt)
	b.PutInt32(a.PushTimeout)
	b.PutInt32(a.Length)
	return nil
}

// Decode implements bin.Decoder.
func (a *AuthenticationCodeTypeFirebaseIos) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFirebaseIos#ff55aa93 to nil")
	}
	if err := b.ConsumeID(AuthenticationCodeTypeFirebaseIosTypeID); err != nil {
		return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AuthenticationCodeTypeFirebaseIos) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFirebaseIos#ff55aa93 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: field receipt: %w", err)
		}
		a.Receipt = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: field push_timeout: %w", err)
		}
		a.PushTimeout = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: field length: %w", err)
		}
		a.Length = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AuthenticationCodeTypeFirebaseIos) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode authenticationCodeTypeFirebaseIos#ff55aa93 as nil")
	}
	b.ObjStart()
	b.PutID("authenticationCodeTypeFirebaseIos")
	b.Comma()
	b.FieldStart("receipt")
	b.PutString(a.Receipt)
	b.Comma()
	b.FieldStart("push_timeout")
	b.PutInt32(a.PushTimeout)
	b.Comma()
	b.FieldStart("length")
	b.PutInt32(a.Length)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AuthenticationCodeTypeFirebaseIos) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode authenticationCodeTypeFirebaseIos#ff55aa93 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("authenticationCodeTypeFirebaseIos"); err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: %w", err)
			}
		case "receipt":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: field receipt: %w", err)
			}
			a.Receipt = value
		case "push_timeout":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: field push_timeout: %w", err)
			}
			a.PushTimeout = value
		case "length":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode authenticationCodeTypeFirebaseIos#ff55aa93: field length: %w", err)
			}
			a.Length = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetReceipt returns value of Receipt field.
func (a *AuthenticationCodeTypeFirebaseIos) GetReceipt() (value string) {
	if a == nil {
		return
	}
	return a.Receipt
}

// GetPushTimeout returns value of PushTimeout field.
func (a *AuthenticationCodeTypeFirebaseIos) GetPushTimeout() (value int32) {
	if a == nil {
		return
	}
	return a.PushTimeout
}

// GetLength returns value of Length field.
func (a *AuthenticationCodeTypeFirebaseIos) GetLength() (value int32) {
	if a == nil {
		return
	}
	return a.Length
}

// AuthenticationCodeTypeClassName is schema name of AuthenticationCodeTypeClass.
const AuthenticationCodeTypeClassName = "AuthenticationCodeType"

// AuthenticationCodeTypeClass represents AuthenticationCodeType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeAuthenticationCodeType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.AuthenticationCodeTypeTelegramMessage: // authenticationCodeTypeTelegramMessage#7bf49b2a
//	case *tdapi.AuthenticationCodeTypeSMS: // authenticationCodeTypeSms#3960e288
//	case *tdapi.AuthenticationCodeTypeSMSWord: // authenticationCodeTypeSmsWord#a6063c63
//	case *tdapi.AuthenticationCodeTypeSMSPhrase: // authenticationCodeTypeSmsPhrase#2ebc8cd1
//	case *tdapi.AuthenticationCodeTypeCall: // authenticationCodeTypeCall#61876c67
//	case *tdapi.AuthenticationCodeTypeFlashCall: // authenticationCodeTypeFlashCall#533379a2
//	case *tdapi.AuthenticationCodeTypeMissedCall: // authenticationCodeTypeMissedCall#29bb0a87
//	case *tdapi.AuthenticationCodeTypeFragment: // authenticationCodeTypeFragment#810f74cd
//	case *tdapi.AuthenticationCodeTypeFirebaseAndroid: // authenticationCodeTypeFirebaseAndroid#6f9bb51e
//	case *tdapi.AuthenticationCodeTypeFirebaseIos: // authenticationCodeTypeFirebaseIos#ff55aa93
//	default: panic(v)
//	}
type AuthenticationCodeTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() AuthenticationCodeTypeClass

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

// DecodeAuthenticationCodeType implements binary de-serialization for AuthenticationCodeTypeClass.
func DecodeAuthenticationCodeType(buf *bin.Buffer) (AuthenticationCodeTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case AuthenticationCodeTypeTelegramMessageTypeID:
		// Decoding authenticationCodeTypeTelegramMessage#7bf49b2a.
		v := AuthenticationCodeTypeTelegramMessage{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeSMSTypeID:
		// Decoding authenticationCodeTypeSms#3960e288.
		v := AuthenticationCodeTypeSMS{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeSMSWordTypeID:
		// Decoding authenticationCodeTypeSmsWord#a6063c63.
		v := AuthenticationCodeTypeSMSWord{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeSMSPhraseTypeID:
		// Decoding authenticationCodeTypeSmsPhrase#2ebc8cd1.
		v := AuthenticationCodeTypeSMSPhrase{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeCallTypeID:
		// Decoding authenticationCodeTypeCall#61876c67.
		v := AuthenticationCodeTypeCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeFlashCallTypeID:
		// Decoding authenticationCodeTypeFlashCall#533379a2.
		v := AuthenticationCodeTypeFlashCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeMissedCallTypeID:
		// Decoding authenticationCodeTypeMissedCall#29bb0a87.
		v := AuthenticationCodeTypeMissedCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeFragmentTypeID:
		// Decoding authenticationCodeTypeFragment#810f74cd.
		v := AuthenticationCodeTypeFragment{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeFirebaseAndroidTypeID:
		// Decoding authenticationCodeTypeFirebaseAndroid#6f9bb51e.
		v := AuthenticationCodeTypeFirebaseAndroid{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthenticationCodeTypeFirebaseIosTypeID:
		// Decoding authenticationCodeTypeFirebaseIos#ff55aa93.
		v := AuthenticationCodeTypeFirebaseIos{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONAuthenticationCodeType implements binary de-serialization for AuthenticationCodeTypeClass.
func DecodeTDLibJSONAuthenticationCodeType(buf tdjson.Decoder) (AuthenticationCodeTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "authenticationCodeTypeTelegramMessage":
		// Decoding authenticationCodeTypeTelegramMessage#7bf49b2a.
		v := AuthenticationCodeTypeTelegramMessage{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeSms":
		// Decoding authenticationCodeTypeSms#3960e288.
		v := AuthenticationCodeTypeSMS{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeSmsWord":
		// Decoding authenticationCodeTypeSmsWord#a6063c63.
		v := AuthenticationCodeTypeSMSWord{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeSmsPhrase":
		// Decoding authenticationCodeTypeSmsPhrase#2ebc8cd1.
		v := AuthenticationCodeTypeSMSPhrase{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeCall":
		// Decoding authenticationCodeTypeCall#61876c67.
		v := AuthenticationCodeTypeCall{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeFlashCall":
		// Decoding authenticationCodeTypeFlashCall#533379a2.
		v := AuthenticationCodeTypeFlashCall{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeMissedCall":
		// Decoding authenticationCodeTypeMissedCall#29bb0a87.
		v := AuthenticationCodeTypeMissedCall{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeFragment":
		// Decoding authenticationCodeTypeFragment#810f74cd.
		v := AuthenticationCodeTypeFragment{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeFirebaseAndroid":
		// Decoding authenticationCodeTypeFirebaseAndroid#6f9bb51e.
		v := AuthenticationCodeTypeFirebaseAndroid{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	case "authenticationCodeTypeFirebaseIos":
		// Decoding authenticationCodeTypeFirebaseIos#ff55aa93.
		v := AuthenticationCodeTypeFirebaseIos{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode AuthenticationCodeTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// AuthenticationCodeType boxes the AuthenticationCodeTypeClass providing a helper.
type AuthenticationCodeTypeBox struct {
	AuthenticationCodeType AuthenticationCodeTypeClass
}

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

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

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

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