// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// AuthSentCode represents TL type `auth.sentCode#5e002502`.
// Contains info about a sent verification code.
//
// See https://core.telegram.org/constructor/auth.sentCode for reference.
type AuthSentCode struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Phone code type
	Type AuthSentCodeTypeClass
	// Phone code hash, to be stored and later re-used with auth.signIn¹
	//
	// Links:
	//  1) https://core.telegram.org/method/auth.signIn
	PhoneCodeHash string
	// Phone code type that will be sent next, if the phone code is not received within
	// timeout seconds: to send it use auth.resendCode¹
	//
	// Links:
	//  1) https://core.telegram.org/method/auth.resendCode
	//
	// Use SetNextType and GetNextType helpers.
	NextType AuthCodeTypeClass
	// Timeout for reception of the phone code
	//
	// Use SetTimeout and GetTimeout helpers.
	Timeout int
}

// AuthSentCodeTypeID is TL type id of AuthSentCode.
const AuthSentCodeTypeID = 0x5e002502

// construct implements constructor of AuthSentCodeClass.
func (s AuthSentCode) construct() AuthSentCodeClass { return &s }

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

	_ AuthSentCodeClass = &AuthSentCode{}
)

func (s *AuthSentCode) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Flags.Zero()) {
		return false
	}
	if !(s.Type == nil) {
		return false
	}
	if !(s.PhoneCodeHash == "") {
		return false
	}
	if !(s.NextType == nil) {
		return false
	}
	if !(s.Timeout == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCode from given interface.
func (s *AuthSentCode) FillFrom(from interface {
	GetType() (value AuthSentCodeTypeClass)
	GetPhoneCodeHash() (value string)
	GetNextType() (value AuthCodeTypeClass, ok bool)
	GetTimeout() (value int, ok bool)
}) {
	s.Type = from.GetType()
	s.PhoneCodeHash = from.GetPhoneCodeHash()
	if val, ok := from.GetNextType(); ok {
		s.NextType = val
	}

	if val, ok := from.GetTimeout(); ok {
		s.Timeout = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (s *AuthSentCode) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCode",
		ID:   AuthSentCodeTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Type",
			SchemaName: "type",
		},
		{
			Name:       "PhoneCodeHash",
			SchemaName: "phone_code_hash",
		},
		{
			Name:       "NextType",
			SchemaName: "next_type",
			Null:       !s.Flags.Has(1),
		},
		{
			Name:       "Timeout",
			SchemaName: "timeout",
			Null:       !s.Flags.Has(2),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (s *AuthSentCode) SetFlags() {
	if !(s.NextType == nil) {
		s.Flags.Set(1)
	}
	if !(s.Timeout == 0) {
		s.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func (s *AuthSentCode) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCode#5e002502 as nil")
	}
	b.PutID(AuthSentCodeTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCode) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCode#5e002502 as nil")
	}
	s.SetFlags()
	if err := s.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode auth.sentCode#5e002502: field flags: %w", err)
	}
	if s.Type == nil {
		return fmt.Errorf("unable to encode auth.sentCode#5e002502: field type is nil")
	}
	if err := s.Type.Encode(b); err != nil {
		return fmt.Errorf("unable to encode auth.sentCode#5e002502: field type: %w", err)
	}
	b.PutString(s.PhoneCodeHash)
	if s.Flags.Has(1) {
		if s.NextType == nil {
			return fmt.Errorf("unable to encode auth.sentCode#5e002502: field next_type is nil")
		}
		if err := s.NextType.Encode(b); err != nil {
			return fmt.Errorf("unable to encode auth.sentCode#5e002502: field next_type: %w", err)
		}
	}
	if s.Flags.Has(2) {
		b.PutInt(s.Timeout)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCode) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCode#5e002502 to nil")
	}
	{
		if err := s.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode auth.sentCode#5e002502: field flags: %w", err)
		}
	}
	{
		value, err := DecodeAuthSentCodeType(b)
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCode#5e002502: field type: %w", err)
		}
		s.Type = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCode#5e002502: field phone_code_hash: %w", err)
		}
		s.PhoneCodeHash = value
	}
	if s.Flags.Has(1) {
		value, err := DecodeAuthCodeType(b)
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCode#5e002502: field next_type: %w", err)
		}
		s.NextType = value
	}
	if s.Flags.Has(2) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCode#5e002502: field timeout: %w", err)
		}
		s.Timeout = value
	}
	return nil
}

// GetType returns value of Type field.
func (s *AuthSentCode) GetType() (value AuthSentCodeTypeClass) {
	if s == nil {
		return
	}
	return s.Type
}

// GetPhoneCodeHash returns value of PhoneCodeHash field.
func (s *AuthSentCode) GetPhoneCodeHash() (value string) {
	if s == nil {
		return
	}
	return s.PhoneCodeHash
}

// SetNextType sets value of NextType conditional field.
func (s *AuthSentCode) SetNextType(value AuthCodeTypeClass) {
	s.Flags.Set(1)
	s.NextType = value
}

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

// SetTimeout sets value of Timeout conditional field.
func (s *AuthSentCode) SetTimeout(value int) {
	s.Flags.Set(2)
	s.Timeout = value
}

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

// AuthSentCodeSuccess represents TL type `auth.sentCodeSuccess#2390fe44`.
// The user successfully authorized using future auth tokens¹
//
// Links:
//  1. https://core.telegram.org/api/auth#future-auth-tokens
//
// See https://core.telegram.org/constructor/auth.sentCodeSuccess for reference.
type AuthSentCodeSuccess struct {
	// Authorization info
	Authorization AuthAuthorizationClass
}

// AuthSentCodeSuccessTypeID is TL type id of AuthSentCodeSuccess.
const AuthSentCodeSuccessTypeID = 0x2390fe44

// construct implements constructor of AuthSentCodeClass.
func (s AuthSentCodeSuccess) construct() AuthSentCodeClass { return &s }

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

	_ AuthSentCodeClass = &AuthSentCodeSuccess{}
)

func (s *AuthSentCodeSuccess) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Authorization == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCodeSuccess from given interface.
func (s *AuthSentCodeSuccess) FillFrom(from interface {
	GetAuthorization() (value AuthAuthorizationClass)
}) {
	s.Authorization = from.GetAuthorization()
}

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

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

// TypeInfo returns info about TL type.
func (s *AuthSentCodeSuccess) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodeSuccess",
		ID:   AuthSentCodeSuccessTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Authorization",
			SchemaName: "authorization",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *AuthSentCodeSuccess) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeSuccess#2390fe44 as nil")
	}
	b.PutID(AuthSentCodeSuccessTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodeSuccess) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodeSuccess#2390fe44 as nil")
	}
	if s.Authorization == nil {
		return fmt.Errorf("unable to encode auth.sentCodeSuccess#2390fe44: field authorization is nil")
	}
	if err := s.Authorization.Encode(b); err != nil {
		return fmt.Errorf("unable to encode auth.sentCodeSuccess#2390fe44: field authorization: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodeSuccess) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodeSuccess#2390fe44 to nil")
	}
	{
		value, err := DecodeAuthAuthorization(b)
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodeSuccess#2390fe44: field authorization: %w", err)
		}
		s.Authorization = value
	}
	return nil
}

// GetAuthorization returns value of Authorization field.
func (s *AuthSentCodeSuccess) GetAuthorization() (value AuthAuthorizationClass) {
	if s == nil {
		return
	}
	return s.Authorization
}

// AuthSentCodePaymentRequired represents TL type `auth.sentCodePaymentRequired#e0955a3c`.
// Official apps may receive this constructor, indicating that due to the high cost of
// SMS verification codes for the user's country/provider, the user must purchase a
// Telegram Premium¹ subscription in order to proceed with the login/signup.
//
// Links:
//  1. https://core.telegram.org/api/premium
//
// See https://core.telegram.org/constructor/auth.sentCodePaymentRequired for reference.
type AuthSentCodePaymentRequired struct {
	// Store identifier of the Telegram Premium subscription.
	StoreProduct string
	// Phone code hash, to be stored and later re-used with auth.signIn¹
	//
	// Links:
	//  1) https://core.telegram.org/method/auth.signIn
	PhoneCodeHash string
	// An email address that can be contacted for more information about this request.
	SupportEmailAddress string
	// The mandatory subject for the email.
	SupportEmailSubject string
	// Currency field of AuthSentCodePaymentRequired.
	Currency string
	// Amount field of AuthSentCodePaymentRequired.
	Amount int64
}

// AuthSentCodePaymentRequiredTypeID is TL type id of AuthSentCodePaymentRequired.
const AuthSentCodePaymentRequiredTypeID = 0xe0955a3c

// construct implements constructor of AuthSentCodeClass.
func (s AuthSentCodePaymentRequired) construct() AuthSentCodeClass { return &s }

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

	_ AuthSentCodeClass = &AuthSentCodePaymentRequired{}
)

func (s *AuthSentCodePaymentRequired) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.StoreProduct == "") {
		return false
	}
	if !(s.PhoneCodeHash == "") {
		return false
	}
	if !(s.SupportEmailAddress == "") {
		return false
	}
	if !(s.SupportEmailSubject == "") {
		return false
	}
	if !(s.Currency == "") {
		return false
	}
	if !(s.Amount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSentCodePaymentRequired from given interface.
func (s *AuthSentCodePaymentRequired) FillFrom(from interface {
	GetStoreProduct() (value string)
	GetPhoneCodeHash() (value string)
	GetSupportEmailAddress() (value string)
	GetSupportEmailSubject() (value string)
	GetCurrency() (value string)
	GetAmount() (value int64)
}) {
	s.StoreProduct = from.GetStoreProduct()
	s.PhoneCodeHash = from.GetPhoneCodeHash()
	s.SupportEmailAddress = from.GetSupportEmailAddress()
	s.SupportEmailSubject = from.GetSupportEmailSubject()
	s.Currency = from.GetCurrency()
	s.Amount = from.GetAmount()
}

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

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

// TypeInfo returns info about TL type.
func (s *AuthSentCodePaymentRequired) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "auth.sentCodePaymentRequired",
		ID:   AuthSentCodePaymentRequiredTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "StoreProduct",
			SchemaName: "store_product",
		},
		{
			Name:       "PhoneCodeHash",
			SchemaName: "phone_code_hash",
		},
		{
			Name:       "SupportEmailAddress",
			SchemaName: "support_email_address",
		},
		{
			Name:       "SupportEmailSubject",
			SchemaName: "support_email_subject",
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
	}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (s *AuthSentCodePaymentRequired) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode auth.sentCodePaymentRequired#e0955a3c as nil")
	}
	b.PutString(s.StoreProduct)
	b.PutString(s.PhoneCodeHash)
	b.PutString(s.SupportEmailAddress)
	b.PutString(s.SupportEmailSubject)
	b.PutString(s.Currency)
	b.PutLong(s.Amount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *AuthSentCodePaymentRequired) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode auth.sentCodePaymentRequired#e0955a3c to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodePaymentRequired#e0955a3c: field store_product: %w", err)
		}
		s.StoreProduct = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodePaymentRequired#e0955a3c: field phone_code_hash: %w", err)
		}
		s.PhoneCodeHash = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodePaymentRequired#e0955a3c: field support_email_address: %w", err)
		}
		s.SupportEmailAddress = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodePaymentRequired#e0955a3c: field support_email_subject: %w", err)
		}
		s.SupportEmailSubject = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodePaymentRequired#e0955a3c: field currency: %w", err)
		}
		s.Currency = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode auth.sentCodePaymentRequired#e0955a3c: field amount: %w", err)
		}
		s.Amount = value
	}
	return nil
}

// GetStoreProduct returns value of StoreProduct field.
func (s *AuthSentCodePaymentRequired) GetStoreProduct() (value string) {
	if s == nil {
		return
	}
	return s.StoreProduct
}

// GetPhoneCodeHash returns value of PhoneCodeHash field.
func (s *AuthSentCodePaymentRequired) GetPhoneCodeHash() (value string) {
	if s == nil {
		return
	}
	return s.PhoneCodeHash
}

// GetSupportEmailAddress returns value of SupportEmailAddress field.
func (s *AuthSentCodePaymentRequired) GetSupportEmailAddress() (value string) {
	if s == nil {
		return
	}
	return s.SupportEmailAddress
}

// GetSupportEmailSubject returns value of SupportEmailSubject field.
func (s *AuthSentCodePaymentRequired) GetSupportEmailSubject() (value string) {
	if s == nil {
		return
	}
	return s.SupportEmailSubject
}

// GetCurrency returns value of Currency field.
func (s *AuthSentCodePaymentRequired) GetCurrency() (value string) {
	if s == nil {
		return
	}
	return s.Currency
}

// GetAmount returns value of Amount field.
func (s *AuthSentCodePaymentRequired) GetAmount() (value int64) {
	if s == nil {
		return
	}
	return s.Amount
}

// AuthSentCodeClassName is schema name of AuthSentCodeClass.
const AuthSentCodeClassName = "auth.SentCode"

// AuthSentCodeClass represents auth.SentCode generic type.
//
// See https://core.telegram.org/type/auth.SentCode for reference.
//
// Example:
//
//	g, err := tg.DecodeAuthSentCode(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.AuthSentCode: // auth.sentCode#5e002502
//	case *tg.AuthSentCodeSuccess: // auth.sentCodeSuccess#2390fe44
//	case *tg.AuthSentCodePaymentRequired: // auth.sentCodePaymentRequired#e0955a3c
//	default: panic(v)
//	}
type AuthSentCodeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() AuthSentCodeClass

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

// DecodeAuthSentCode implements binary de-serialization for AuthSentCodeClass.
func DecodeAuthSentCode(buf *bin.Buffer) (AuthSentCodeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case AuthSentCodeTypeID:
		// Decoding auth.sentCode#5e002502.
		v := AuthSentCode{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodeSuccessTypeID:
		// Decoding auth.sentCodeSuccess#2390fe44.
		v := AuthSentCodeSuccess{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", err)
		}
		return &v, nil
	case AuthSentCodePaymentRequiredTypeID:
		// Decoding auth.sentCodePaymentRequired#e0955a3c.
		v := AuthSentCodePaymentRequired{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", bin.NewUnexpectedID(id))
	}
}

// AuthSentCode boxes the AuthSentCodeClass providing a helper.
type AuthSentCodeBox struct {
	SentCode AuthSentCodeClass
}

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

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