// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// 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 ( AuthSentCode) () AuthSentCodeClass { return & }

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

	_ AuthSentCodeClass = &AuthSentCode{}
)

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

	return true
}

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

// FillFrom fills AuthSentCode from given interface.
func ( *AuthSentCode) ( interface {
	() ( AuthSentCodeTypeClass)
	() ( string)
	() ( AuthCodeTypeClass,  bool)
	() ( int,  bool)
}) {
	.Type = .()
	.PhoneCodeHash = .()
	if ,  := .();  {
		.NextType = 
	}

	if ,  := .();  {
		.Timeout = 
	}

}

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

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

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

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

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

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

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

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

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

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

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

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

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

// GetTimeout returns value of Timeout conditional field and
// boolean which is true if field was set.
func ( *AuthSentCode) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .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 ( AuthSentCodeSuccess) () AuthSentCodeClass { return & }

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

	_ AuthSentCodeClass = &AuthSentCodeSuccess{}
)

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

	return true
}

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

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

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

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

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

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

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

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

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

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

// 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
//	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 ( *bin.Buffer) (AuthSentCodeClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case AuthSentCodeTypeID:
		// Decoding auth.sentCode#5e002502.
		 := AuthSentCode{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", )
		}
		return &, nil
	case AuthSentCodeSuccessTypeID:
		// Decoding auth.sentCodeSuccess#2390fe44.
		 := AuthSentCodeSuccess{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode AuthSentCodeClass: %w", bin.NewUnexpectedID())
	}
}

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

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

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