// Code generated by gotdgen, DO NOT EDIT.

package tg

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

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// AuthSentCodeTypeApp represents TL type `auth.sentCodeTypeApp#3dbb5986`.
// The code was sent through the telegram app
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeApp for reference.
type AuthSentCodeTypeApp struct {
	// Length of the code in bytes
	Length int
}

// AuthSentCodeTypeAppTypeID is TL type id of AuthSentCodeTypeApp.
const AuthSentCodeTypeAppTypeID = 0x3dbb5986

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeApp) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeApp{}
)

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

	return true
}

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

// FillFrom fills AuthSentCodeTypeApp from given interface.
func (s *AuthSentCodeTypeApp) FillFrom(from interface {
	GetLength() (value int)
}) {
	s.Length = from.GetLength()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeApp) TypeName() string {
	return "auth.sentCodeTypeApp"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeApp) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeApp",
		ID:   AuthSentCodeTypeAppTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeApp) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeApp#3dbb5986 as nil")
	}
	b.PutID(AuthSentCodeTypeAppTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeApp) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeApp#3dbb5986 as nil")
	}
	b.PutInt(s.Length)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeApp) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeApp#3dbb5986 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeAppTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeApp#3dbb5986: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeApp) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeApp#3dbb5986 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeApp#3dbb5986: field length: %w", err)
		}
		s.Length = value
	}
	return nil
}

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeApp) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// AuthSentCodeTypeSMS represents TL type `auth.sentCodeTypeSms#c000bba2`.
// The code was sent via SMS
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeSms for reference.
type AuthSentCodeTypeSMS struct {
	// Length of the code in bytes
	Length int
}

// AuthSentCodeTypeSMSTypeID is TL type id of AuthSentCodeTypeSMS.
const AuthSentCodeTypeSMSTypeID = 0xc000bba2

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeSMS) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeSMS{}
)

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

	return true
}

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

// FillFrom fills AuthSentCodeTypeSMS from given interface.
func (s *AuthSentCodeTypeSMS) FillFrom(from interface {
	GetLength() (value int)
}) {
	s.Length = from.GetLength()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeSMS) TypeName() string {
	return "auth.sentCodeTypeSms"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeSMS) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeSms",
		ID:   AuthSentCodeTypeSMSTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeSMS) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeSms#c000bba2 as nil")
	}
	b.PutID(AuthSentCodeTypeSMSTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeSMS) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeSms#c000bba2 as nil")
	}
	b.PutInt(s.Length)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeSMS) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeSms#c000bba2 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeSMSTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeSms#c000bba2: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeSMS) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeSms#c000bba2 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeSms#c000bba2: field length: %w", err)
		}
		s.Length = value
	}
	return nil
}

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeSMS) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// AuthSentCodeTypeCall represents TL type `auth.sentCodeTypeCall#5353e5a7`.
// The code will be sent via a phone call: a synthesized voice will tell the user which
// verification code to input.
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeCall for reference.
type AuthSentCodeTypeCall struct {
	// Length of the verification code
	Length int
}

// AuthSentCodeTypeCallTypeID is TL type id of AuthSentCodeTypeCall.
const AuthSentCodeTypeCallTypeID = 0x5353e5a7

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeCall) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeCall{}
)

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

	return true
}

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

// FillFrom fills AuthSentCodeTypeCall from given interface.
func (s *AuthSentCodeTypeCall) FillFrom(from interface {
	GetLength() (value int)
}) {
	s.Length = from.GetLength()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeCall) TypeName() string {
	return "auth.sentCodeTypeCall"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeCall",
		ID:   AuthSentCodeTypeCallTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeCall) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeCall#5353e5a7 as nil")
	}
	b.PutID(AuthSentCodeTypeCallTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeCall) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeCall#5353e5a7 as nil")
	}
	b.PutInt(s.Length)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeCall) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeCall#5353e5a7 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeCallTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeCall#5353e5a7: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeCall) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeCall#5353e5a7 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeCall#5353e5a7: field length: %w", err)
		}
		s.Length = value
	}
	return nil
}

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeCall) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// AuthSentCodeTypeFlashCall represents TL type `auth.sentCodeTypeFlashCall#ab03c6d9`.
// The code will be sent via a flash phone call, that will be closed immediately. The
// phone code will then be the phone number itself, just make sure that the phone number
// matches the specified pattern.
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeFlashCall for reference.
type AuthSentCodeTypeFlashCall struct {
	// pattern¹ to match
	//
	// Links:
	//  1) https://core.telegram.org/api/pattern
	Pattern string
}

// AuthSentCodeTypeFlashCallTypeID is TL type id of AuthSentCodeTypeFlashCall.
const AuthSentCodeTypeFlashCallTypeID = 0xab03c6d9

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeFlashCall) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeFlashCall{}
)

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

	return true
}

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

// FillFrom fills AuthSentCodeTypeFlashCall from given interface.
func (s *AuthSentCodeTypeFlashCall) FillFrom(from interface {
	GetPattern() (value string)
}) {
	s.Pattern = from.GetPattern()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeFlashCall) TypeName() string {
	return "auth.sentCodeTypeFlashCall"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeFlashCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeFlashCall",
		ID:   AuthSentCodeTypeFlashCallTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Pattern",
			SchemaName: "pattern",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeFlashCall) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeFlashCall#ab03c6d9 as nil")
	}
	b.PutID(AuthSentCodeTypeFlashCallTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeFlashCall) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeFlashCall#ab03c6d9 as nil")
	}
	b.PutString(s.Pattern)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeFlashCall) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeFlashCall#ab03c6d9 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeFlashCallTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeFlashCall#ab03c6d9: %w", err)
	}
	return s.DecodeBare(b)
}

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

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

// AuthSentCodeTypeMissedCall represents TL type `auth.sentCodeTypeMissedCall#82006484`.
// The code will be sent via a flash phone call, that will be closed immediately. The
// last digits of the phone number that calls are the code that must be entered manually
// by the user.
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeMissedCall for reference.
type AuthSentCodeTypeMissedCall struct {
	// Prefix of the phone number from which the call will be made
	Prefix string
	// Length of the verification code
	Length int
}

// AuthSentCodeTypeMissedCallTypeID is TL type id of AuthSentCodeTypeMissedCall.
const AuthSentCodeTypeMissedCallTypeID = 0x82006484

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeMissedCall) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeMissedCall{}
)

func (s *AuthSentCodeTypeMissedCall) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Prefix == "") {
		return false
	}
	if !(s.Length == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCodeTypeMissedCall from given interface.
func (s *AuthSentCodeTypeMissedCall) FillFrom(from interface {
	GetPrefix() (value string)
	GetLength() (value int)
}) {
	s.Prefix = from.GetPrefix()
	s.Length = from.GetLength()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeMissedCall) TypeName() string {
	return "auth.sentCodeTypeMissedCall"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeMissedCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeMissedCall",
		ID:   AuthSentCodeTypeMissedCallTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Prefix",
			SchemaName: "prefix",
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeMissedCall) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeMissedCall#82006484 as nil")
	}
	b.PutID(AuthSentCodeTypeMissedCallTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeMissedCall) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeMissedCall#82006484 as nil")
	}
	b.PutString(s.Prefix)
	b.PutInt(s.Length)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeMissedCall) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeMissedCall#82006484 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeMissedCallTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeMissedCall#82006484: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeMissedCall) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeMissedCall#82006484 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeMissedCall#82006484: field prefix: %w", err)
		}
		s.Prefix = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeMissedCall#82006484: field length: %w", err)
		}
		s.Length = value
	}
	return nil
}

// GetPrefix returns value of Prefix field.
func (s *AuthSentCodeTypeMissedCall) GetPrefix() (value string) {
	if s == nil {
		return
	}
	return s.Prefix
}

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeMissedCall) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// AuthSentCodeTypeEmailCode represents TL type `auth.sentCodeTypeEmailCode#f450f59b`.
// The code was sent via the previously configured login email »¹
//
// Links:
//  1. https://core.telegram.org/api/auth#email-verification
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeEmailCode for reference.
type AuthSentCodeTypeEmailCode struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether authorization through Apple ID is allowed
	AppleSigninAllowed bool
	// Whether authorization through Google ID is allowed
	GoogleSigninAllowed bool
	// Pattern¹ of the email
	//
	// Links:
	//  1) https://core.telegram.org/api/pattern
	EmailPattern string
	// Length of the sent verification code
	Length int
	// Clients should wait for the specified amount of seconds before allowing the user to
	// invoke auth.resetLoginEmail¹ (will be 0 for Premium² users).
	//
	// Links:
	//  1) https://core.telegram.org/method/auth.resetLoginEmail
	//  2) https://core.telegram.org/api/premium
	//
	// Use SetResetAvailablePeriod and GetResetAvailablePeriod helpers.
	ResetAvailablePeriod int
	// An email reset was already requested, and will occur at the specified date.
	//
	// Use SetResetPendingDate and GetResetPendingDate helpers.
	ResetPendingDate int
}

// AuthSentCodeTypeEmailCodeTypeID is TL type id of AuthSentCodeTypeEmailCode.
const AuthSentCodeTypeEmailCodeTypeID = 0xf450f59b

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeEmailCode) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeEmailCode{}
)

func (s *AuthSentCodeTypeEmailCode) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Flags.Zero()) {
		return false
	}
	if !(s.AppleSigninAllowed == false) {
		return false
	}
	if !(s.GoogleSigninAllowed == false) {
		return false
	}
	if !(s.EmailPattern == "") {
		return false
	}
	if !(s.Length == 0) {
		return false
	}
	if !(s.ResetAvailablePeriod == 0) {
		return false
	}
	if !(s.ResetPendingDate == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCodeTypeEmailCode from given interface.
func (s *AuthSentCodeTypeEmailCode) FillFrom(from interface {
	GetAppleSigninAllowed() (value bool)
	GetGoogleSigninAllowed() (value bool)
	GetEmailPattern() (value string)
	GetLength() (value int)
	GetResetAvailablePeriod() (value int, ok bool)
	GetResetPendingDate() (value int, ok bool)
}) {
	s.AppleSigninAllowed = from.GetAppleSigninAllowed()
	s.GoogleSigninAllowed = from.GetGoogleSigninAllowed()
	s.EmailPattern = from.GetEmailPattern()
	s.Length = from.GetLength()
	if val, ok := from.GetResetAvailablePeriod(); ok {
		s.ResetAvailablePeriod = val
	}

	if val, ok := from.GetResetPendingDate(); ok {
		s.ResetPendingDate = val
	}

}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeEmailCode) TypeName() string {
	return "auth.sentCodeTypeEmailCode"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeEmailCode) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeEmailCode",
		ID:   AuthSentCodeTypeEmailCodeTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "AppleSigninAllowed",
			SchemaName: "apple_signin_allowed",
			Null:       !s.Flags.Has(0),
		},
		{
			Name:       "GoogleSigninAllowed",
			SchemaName: "google_signin_allowed",
			Null:       !s.Flags.Has(1),
		},
		{
			Name:       "EmailPattern",
			SchemaName: "email_pattern",
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
		{
			Name:       "ResetAvailablePeriod",
			SchemaName: "reset_available_period",
			Null:       !s.Flags.Has(3),
		},
		{
			Name:       "ResetPendingDate",
			SchemaName: "reset_pending_date",
			Null:       !s.Flags.Has(4),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (s *AuthSentCodeTypeEmailCode) SetFlags() {
	if !(s.AppleSigninAllowed == false) {
		s.Flags.Set(0)
	}
	if !(s.GoogleSigninAllowed == false) {
		s.Flags.Set(1)
	}
	if !(s.ResetAvailablePeriod == 0) {
		s.Flags.Set(3)
	}
	if !(s.ResetPendingDate == 0) {
		s.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeEmailCode) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeEmailCode#f450f59b as nil")
	}
	b.PutID(AuthSentCodeTypeEmailCodeTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeEmailCode) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeEmailCode#f450f59b as nil")
	}
	s.SetFlags()
	if err := s.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode auth.sentCodeTypeEmailCode#f450f59b: field flags: %w", err)
	}
	b.PutString(s.EmailPattern)
	b.PutInt(s.Length)
	if s.Flags.Has(3) {
		b.PutInt(s.ResetAvailablePeriod)
	}
	if s.Flags.Has(4) {
		b.PutInt(s.ResetPendingDate)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeEmailCode) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeEmailCode#f450f59b to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeEmailCodeTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeEmailCode#f450f59b: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeEmailCode) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeEmailCode#f450f59b to nil")
	}
	{
		if err := s.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeEmailCode#f450f59b: field flags: %w", err)
		}
	}
	s.AppleSigninAllowed = s.Flags.Has(0)
	s.GoogleSigninAllowed = s.Flags.Has(1)
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeEmailCode#f450f59b: field email_pattern: %w", err)
		}
		s.EmailPattern = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeEmailCode#f450f59b: field length: %w", err)
		}
		s.Length = value
	}
	if s.Flags.Has(3) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeEmailCode#f450f59b: field reset_available_period: %w", err)
		}
		s.ResetAvailablePeriod = value
	}
	if s.Flags.Has(4) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeEmailCode#f450f59b: field reset_pending_date: %w", err)
		}
		s.ResetPendingDate = value
	}
	return nil
}

// SetAppleSigninAllowed sets value of AppleSigninAllowed conditional field.
func (s *AuthSentCodeTypeEmailCode) SetAppleSigninAllowed(value bool) {
	if value {
		s.Flags.Set(0)
		s.AppleSigninAllowed = true
	} else {
		s.Flags.Unset(0)
		s.AppleSigninAllowed = false
	}
}

// GetAppleSigninAllowed returns value of AppleSigninAllowed conditional field.
func (s *AuthSentCodeTypeEmailCode) GetAppleSigninAllowed() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(0)
}

// SetGoogleSigninAllowed sets value of GoogleSigninAllowed conditional field.
func (s *AuthSentCodeTypeEmailCode) SetGoogleSigninAllowed(value bool) {
	if value {
		s.Flags.Set(1)
		s.GoogleSigninAllowed = true
	} else {
		s.Flags.Unset(1)
		s.GoogleSigninAllowed = false
	}
}

// GetGoogleSigninAllowed returns value of GoogleSigninAllowed conditional field.
func (s *AuthSentCodeTypeEmailCode) GetGoogleSigninAllowed() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(1)
}

// GetEmailPattern returns value of EmailPattern field.
func (s *AuthSentCodeTypeEmailCode) GetEmailPattern() (value string) {
	if s == nil {
		return
	}
	return s.EmailPattern
}

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeEmailCode) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// SetResetAvailablePeriod sets value of ResetAvailablePeriod conditional field.
func (s *AuthSentCodeTypeEmailCode) SetResetAvailablePeriod(value int) {
	s.Flags.Set(3)
	s.ResetAvailablePeriod = value
}

// GetResetAvailablePeriod returns value of ResetAvailablePeriod conditional field and
// boolean which is true if field was set.
func (s *AuthSentCodeTypeEmailCode) GetResetAvailablePeriod() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(3) {
		return value, false
	}
	return s.ResetAvailablePeriod, true
}

// SetResetPendingDate sets value of ResetPendingDate conditional field.
func (s *AuthSentCodeTypeEmailCode) SetResetPendingDate(value int) {
	s.Flags.Set(4)
	s.ResetPendingDate = value
}

// GetResetPendingDate returns value of ResetPendingDate conditional field and
// boolean which is true if field was set.
func (s *AuthSentCodeTypeEmailCode) GetResetPendingDate() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(4) {
		return value, false
	}
	return s.ResetPendingDate, true
}

// AuthSentCodeTypeSetUpEmailRequired represents TL type `auth.sentCodeTypeSetUpEmailRequired#a5491dea`.
// The user should add and verify an email address in order to login as described here
// »¹.
//
// Links:
//  1. https://core.telegram.org/api/auth#email-verification
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeSetUpEmailRequired for reference.
type AuthSentCodeTypeSetUpEmailRequired struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether authorization through Apple ID is allowed
	AppleSigninAllowed bool
	// Whether authorization through Google ID is allowed
	GoogleSigninAllowed bool
}

// AuthSentCodeTypeSetUpEmailRequiredTypeID is TL type id of AuthSentCodeTypeSetUpEmailRequired.
const AuthSentCodeTypeSetUpEmailRequiredTypeID = 0xa5491dea

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeSetUpEmailRequired) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeSetUpEmailRequired{}
)

func (s *AuthSentCodeTypeSetUpEmailRequired) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Flags.Zero()) {
		return false
	}
	if !(s.AppleSigninAllowed == false) {
		return false
	}
	if !(s.GoogleSigninAllowed == false) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCodeTypeSetUpEmailRequired from given interface.
func (s *AuthSentCodeTypeSetUpEmailRequired) FillFrom(from interface {
	GetAppleSigninAllowed() (value bool)
	GetGoogleSigninAllowed() (value bool)
}) {
	s.AppleSigninAllowed = from.GetAppleSigninAllowed()
	s.GoogleSigninAllowed = from.GetGoogleSigninAllowed()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeSetUpEmailRequired) TypeName() string {
	return "auth.sentCodeTypeSetUpEmailRequired"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeSetUpEmailRequired) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeSetUpEmailRequired",
		ID:   AuthSentCodeTypeSetUpEmailRequiredTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "AppleSigninAllowed",
			SchemaName: "apple_signin_allowed",
			Null:       !s.Flags.Has(0),
		},
		{
			Name:       "GoogleSigninAllowed",
			SchemaName: "google_signin_allowed",
			Null:       !s.Flags.Has(1),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (s *AuthSentCodeTypeSetUpEmailRequired) SetFlags() {
	if !(s.AppleSigninAllowed == false) {
		s.Flags.Set(0)
	}
	if !(s.GoogleSigninAllowed == false) {
		s.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeSetUpEmailRequired) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeSetUpEmailRequired#a5491dea as nil")
	}
	b.PutID(AuthSentCodeTypeSetUpEmailRequiredTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeSetUpEmailRequired) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeSetUpEmailRequired#a5491dea as nil")
	}
	s.SetFlags()
	if err := s.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode auth.sentCodeTypeSetUpEmailRequired#a5491dea: field flags: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeSetUpEmailRequired) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeSetUpEmailRequired#a5491dea to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeSetUpEmailRequiredTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeSetUpEmailRequired#a5491dea: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeSetUpEmailRequired) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeSetUpEmailRequired#a5491dea to nil")
	}
	{
		if err := s.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeSetUpEmailRequired#a5491dea: field flags: %w", err)
		}
	}
	s.AppleSigninAllowed = s.Flags.Has(0)
	s.GoogleSigninAllowed = s.Flags.Has(1)
	return nil
}

// SetAppleSigninAllowed sets value of AppleSigninAllowed conditional field.
func (s *AuthSentCodeTypeSetUpEmailRequired) SetAppleSigninAllowed(value bool) {
	if value {
		s.Flags.Set(0)
		s.AppleSigninAllowed = true
	} else {
		s.Flags.Unset(0)
		s.AppleSigninAllowed = false
	}
}

// GetAppleSigninAllowed returns value of AppleSigninAllowed conditional field.
func (s *AuthSentCodeTypeSetUpEmailRequired) GetAppleSigninAllowed() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(0)
}

// SetGoogleSigninAllowed sets value of GoogleSigninAllowed conditional field.
func (s *AuthSentCodeTypeSetUpEmailRequired) SetGoogleSigninAllowed(value bool) {
	if value {
		s.Flags.Set(1)
		s.GoogleSigninAllowed = true
	} else {
		s.Flags.Unset(1)
		s.GoogleSigninAllowed = false
	}
}

// GetGoogleSigninAllowed returns value of GoogleSigninAllowed conditional field.
func (s *AuthSentCodeTypeSetUpEmailRequired) GetGoogleSigninAllowed() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(1)
}

// AuthSentCodeTypeFragmentSMS represents TL type `auth.sentCodeTypeFragmentSms#d9565c39`.
// The code was delivered via fragment.com¹.
//
// Links:
//  1. https://fragment.com
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeFragmentSms for reference.
type AuthSentCodeTypeFragmentSMS struct {
	// Open the specified URL to log into fragment.com¹ with the wallet that owns the
	// specified phone number and view the code.
	//
	// Links:
	//  1) https://fragment.com
	URL string
	// Length of the delivered code.
	Length int
}

// AuthSentCodeTypeFragmentSMSTypeID is TL type id of AuthSentCodeTypeFragmentSMS.
const AuthSentCodeTypeFragmentSMSTypeID = 0xd9565c39

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeFragmentSMS) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeFragmentSMS{}
)

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

	return true
}

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

// FillFrom fills AuthSentCodeTypeFragmentSMS from given interface.
func (s *AuthSentCodeTypeFragmentSMS) FillFrom(from interface {
	GetURL() (value string)
	GetLength() (value int)
}) {
	s.URL = from.GetURL()
	s.Length = from.GetLength()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeFragmentSMS) TypeName() string {
	return "auth.sentCodeTypeFragmentSms"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeFragmentSMS) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeFragmentSms",
		ID:   AuthSentCodeTypeFragmentSMSTypeID,
	}
	if s == 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 (s *AuthSentCodeTypeFragmentSMS) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeFragmentSms#d9565c39 as nil")
	}
	b.PutID(AuthSentCodeTypeFragmentSMSTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeFragmentSMS) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeFragmentSms#d9565c39 as nil")
	}
	b.PutString(s.URL)
	b.PutInt(s.Length)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeFragmentSMS) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeFragmentSms#d9565c39 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeFragmentSMSTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeFragmentSms#d9565c39: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeFragmentSMS) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeFragmentSms#d9565c39 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFragmentSms#d9565c39: field url: %w", err)
		}
		s.URL = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFragmentSms#d9565c39: field length: %w", err)
		}
		s.Length = value
	}
	return nil
}

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

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeFragmentSMS) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// AuthSentCodeTypeFirebaseSMS represents TL type `auth.sentCodeTypeFirebaseSms#e57b1432`.
// An authentication code should be delivered via SMS after Firebase attestation, as
// described in the auth documentation »¹.
//
// Links:
//  1. https://core.telegram.org/api/auth
//
// See https://core.telegram.org/constructor/auth.sentCodeTypeFirebaseSms for reference.
type AuthSentCodeTypeFirebaseSMS struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// On Android, the nonce to be used as described in the auth documentation »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/auth
	//
	// Use SetNonce and GetNonce helpers.
	Nonce []byte
	// On iOS, must be compared with the receipt extracted from the received push
	// notification.
	//
	// Use SetReceipt and GetReceipt helpers.
	Receipt string
	// On iOS: if a push notification with the ios_push_secret isn't received within
	// push_timeout seconds, the next_type authentication method must be used, with auth
	// resendCode¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/auth.resendCode
	//
	// Use SetPushTimeout and GetPushTimeout helpers.
	PushTimeout int
	// Length of the code that will be delivered.
	Length int
}

// AuthSentCodeTypeFirebaseSMSTypeID is TL type id of AuthSentCodeTypeFirebaseSMS.
const AuthSentCodeTypeFirebaseSMSTypeID = 0xe57b1432

// construct implements constructor of AuthSentCodeTypeClass.
func (s AuthSentCodeTypeFirebaseSMS) construct() AuthSentCodeTypeClass { return &s }

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

	_ AuthSentCodeTypeClass = &AuthSentCodeTypeFirebaseSMS{}
)

func (s *AuthSentCodeTypeFirebaseSMS) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Flags.Zero()) {
		return false
	}
	if !(s.Nonce == nil) {
		return false
	}
	if !(s.Receipt == "") {
		return false
	}
	if !(s.PushTimeout == 0) {
		return false
	}
	if !(s.Length == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCodeTypeFirebaseSMS from given interface.
func (s *AuthSentCodeTypeFirebaseSMS) FillFrom(from interface {
	GetNonce() (value []byte, ok bool)
	GetReceipt() (value string, ok bool)
	GetPushTimeout() (value int, ok bool)
	GetLength() (value int)
}) {
	if val, ok := from.GetNonce(); ok {
		s.Nonce = val
	}

	if val, ok := from.GetReceipt(); ok {
		s.Receipt = val
	}

	if val, ok := from.GetPushTimeout(); ok {
		s.PushTimeout = val
	}

	s.Length = from.GetLength()
}

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

// TypeName returns name of type in TL schema.
func (*AuthSentCodeTypeFirebaseSMS) TypeName() string {
	return "auth.sentCodeTypeFirebaseSms"
}

// TypeInfo returns info about TL type.
func (s *AuthSentCodeTypeFirebaseSMS) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeTypeFirebaseSms",
		ID:   AuthSentCodeTypeFirebaseSMSTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Nonce",
			SchemaName: "nonce",
			Null:       !s.Flags.Has(0),
		},
		{
			Name:       "Receipt",
			SchemaName: "receipt",
			Null:       !s.Flags.Has(1),
		},
		{
			Name:       "PushTimeout",
			SchemaName: "push_timeout",
			Null:       !s.Flags.Has(1),
		},
		{
			Name:       "Length",
			SchemaName: "length",
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (s *AuthSentCodeTypeFirebaseSMS) SetFlags() {
	if !(s.Nonce == nil) {
		s.Flags.Set(0)
	}
	if !(s.Receipt == "") {
		s.Flags.Set(1)
	}
	if !(s.PushTimeout == 0) {
		s.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeTypeFirebaseSMS) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeFirebaseSms#e57b1432 as nil")
	}
	b.PutID(AuthSentCodeTypeFirebaseSMSTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeTypeFirebaseSMS) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeTypeFirebaseSms#e57b1432 as nil")
	}
	s.SetFlags()
	if err := s.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode auth.sentCodeTypeFirebaseSms#e57b1432: field flags: %w", err)
	}
	if s.Flags.Has(0) {
		b.PutBytes(s.Nonce)
	}
	if s.Flags.Has(1) {
		b.PutString(s.Receipt)
	}
	if s.Flags.Has(1) {
		b.PutInt(s.PushTimeout)
	}
	b.PutInt(s.Length)
	return nil
}

// Decode implements bin.Decoder.
func (s *AuthSentCodeTypeFirebaseSMS) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeFirebaseSms#e57b1432 to nil")
	}
	if err := b.ConsumeID(AuthSentCodeTypeFirebaseSMSTypeID); err != nil {
		return fmt.Errorf("unable to decode auth.sentCodeTypeFirebaseSms#e57b1432: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeTypeFirebaseSMS) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeTypeFirebaseSms#e57b1432 to nil")
	}
	{
		if err := s.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFirebaseSms#e57b1432: field flags: %w", err)
		}
	}
	if s.Flags.Has(0) {
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFirebaseSms#e57b1432: field nonce: %w", err)
		}
		s.Nonce = value
	}
	if s.Flags.Has(1) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFirebaseSms#e57b1432: field receipt: %w", err)
		}
		s.Receipt = value
	}
	if s.Flags.Has(1) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFirebaseSms#e57b1432: field push_timeout: %w", err)
		}
		s.PushTimeout = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeTypeFirebaseSms#e57b1432: field length: %w", err)
		}
		s.Length = value
	}
	return nil
}

// SetNonce sets value of Nonce conditional field.
func (s *AuthSentCodeTypeFirebaseSMS) SetNonce(value []byte) {
	s.Flags.Set(0)
	s.Nonce = value
}

// GetNonce returns value of Nonce conditional field and
// boolean which is true if field was set.
func (s *AuthSentCodeTypeFirebaseSMS) GetNonce() (value []byte, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(0) {
		return value, false
	}
	return s.Nonce, true
}

// SetReceipt sets value of Receipt conditional field.
func (s *AuthSentCodeTypeFirebaseSMS) SetReceipt(value string) {
	s.Flags.Set(1)
	s.Receipt = value
}

// GetReceipt returns value of Receipt conditional field and
// boolean which is true if field was set.
func (s *AuthSentCodeTypeFirebaseSMS) GetReceipt() (value string, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(1) {
		return value, false
	}
	return s.Receipt, true
}

// SetPushTimeout sets value of PushTimeout conditional field.
func (s *AuthSentCodeTypeFirebaseSMS) SetPushTimeout(value int) {
	s.Flags.Set(1)
	s.PushTimeout = value
}

// GetPushTimeout returns value of PushTimeout conditional field and
// boolean which is true if field was set.
func (s *AuthSentCodeTypeFirebaseSMS) GetPushTimeout() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(1) {
		return value, false
	}
	return s.PushTimeout, true
}

// GetLength returns value of Length field.
func (s *AuthSentCodeTypeFirebaseSMS) GetLength() (value int) {
	if s == nil {
		return
	}
	return s.Length
}

// AuthSentCodeTypeClassName is schema name of AuthSentCodeTypeClass.
const AuthSentCodeTypeClassName = "auth.SentCodeType"

// AuthSentCodeTypeClass represents auth.SentCodeType generic type.
//
// See https://core.telegram.org/type/auth.SentCodeType for reference.
//
// Example:
//
//	g, err := tg.DecodeAuthSentCodeType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.AuthSentCodeTypeApp: // auth.sentCodeTypeApp#3dbb5986
//	case *tg.AuthSentCodeTypeSMS: // auth.sentCodeTypeSms#c000bba2
//	case *tg.AuthSentCodeTypeCall: // auth.sentCodeTypeCall#5353e5a7
//	case *tg.AuthSentCodeTypeFlashCall: // auth.sentCodeTypeFlashCall#ab03c6d9
//	case *tg.AuthSentCodeTypeMissedCall: // auth.sentCodeTypeMissedCall#82006484
//	case *tg.AuthSentCodeTypeEmailCode: // auth.sentCodeTypeEmailCode#f450f59b
//	case *tg.AuthSentCodeTypeSetUpEmailRequired: // auth.sentCodeTypeSetUpEmailRequired#a5491dea
//	case *tg.AuthSentCodeTypeFragmentSMS: // auth.sentCodeTypeFragmentSms#d9565c39
//	case *tg.AuthSentCodeTypeFirebaseSMS: // auth.sentCodeTypeFirebaseSms#e57b1432
//	default: panic(v)
//	}
type AuthSentCodeTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() AuthSentCodeTypeClass

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

// DecodeAuthSentCodeType implements binary de-serialization for AuthSentCodeTypeClass.
func DecodeAuthSentCodeType(buf *bin.Buffer) (AuthSentCodeTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case AuthSentCodeTypeAppTypeID:
		// Decoding auth.sentCodeTypeApp#3dbb5986.
		v := AuthSentCodeTypeApp{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeSMSTypeID:
		// Decoding auth.sentCodeTypeSms#c000bba2.
		v := AuthSentCodeTypeSMS{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeCallTypeID:
		// Decoding auth.sentCodeTypeCall#5353e5a7.
		v := AuthSentCodeTypeCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeFlashCallTypeID:
		// Decoding auth.sentCodeTypeFlashCall#ab03c6d9.
		v := AuthSentCodeTypeFlashCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeMissedCallTypeID:
		// Decoding auth.sentCodeTypeMissedCall#82006484.
		v := AuthSentCodeTypeMissedCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeEmailCodeTypeID:
		// Decoding auth.sentCodeTypeEmailCode#f450f59b.
		v := AuthSentCodeTypeEmailCode{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeSetUpEmailRequiredTypeID:
		// Decoding auth.sentCodeTypeSetUpEmailRequired#a5491dea.
		v := AuthSentCodeTypeSetUpEmailRequired{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeFragmentSMSTypeID:
		// Decoding auth.sentCodeTypeFragmentSms#d9565c39.
		v := AuthSentCodeTypeFragmentSMS{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeTypeFirebaseSMSTypeID:
		// Decoding auth.sentCodeTypeFirebaseSms#e57b1432.
		v := AuthSentCodeTypeFirebaseSMS{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode AuthSentCodeTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// AuthSentCodeType boxes the AuthSentCodeTypeClass providing a helper.
type AuthSentCodeTypeBox struct {
	SentCodeType AuthSentCodeTypeClass
}

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

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