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

// AuthAuthorization represents TL type `auth.authorization#2ea2c0d4`.
// Contains user authorization info.
//
// See https://core.telegram.org/constructor/auth.authorization for reference.
type AuthAuthorization struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Suggests the user to set up a 2-step verification password to be able to log in again
	SetupPasswordRequired bool
	// Iff setup_password_required is set and the user declines to set a 2-step verification
	// password, they will be able to log into their account via SMS again only after this
	// many days pass.
	//
	// Use SetOtherwiseReloginDays and GetOtherwiseReloginDays helpers.
	OtherwiseReloginDays int
	// Temporary passport¹ sessions
	//
	// Links:
	//  1) https://core.telegram.org/passport
	//
	// Use SetTmpSessions and GetTmpSessions helpers.
	TmpSessions int
	// A future auth token¹
	//
	// Links:
	//  1) https://core.telegram.org/api/auth#future-auth-tokens
	//
	// Use SetFutureAuthToken and GetFutureAuthToken helpers.
	FutureAuthToken []byte
	// Info on authorized user
	User UserClass
}

// AuthAuthorizationTypeID is TL type id of AuthAuthorization.
const AuthAuthorizationTypeID = 0x2ea2c0d4

// construct implements constructor of AuthAuthorizationClass.
func ( AuthAuthorization) () AuthAuthorizationClass { return & }

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

	_ AuthAuthorizationClass = &AuthAuthorization{}
)

func ( *AuthAuthorization) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.SetupPasswordRequired == false) {
		return false
	}
	if !(.OtherwiseReloginDays == 0) {
		return false
	}
	if !(.TmpSessions == 0) {
		return false
	}
	if !(.FutureAuthToken == nil) {
		return false
	}
	if !(.User == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AuthAuthorization from given interface.
func ( *AuthAuthorization) ( interface {
	() ( bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( []byte,  bool)
	() ( UserClass)
}) {
	.SetupPasswordRequired = .()
	if ,  := .();  {
		.OtherwiseReloginDays = 
	}

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

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

	.User = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *AuthAuthorization) () tdp.Type {
	 := tdp.Type{
		Name: "auth.authorization",
		ID:   AuthAuthorizationTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "SetupPasswordRequired",
			SchemaName: "setup_password_required",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "OtherwiseReloginDays",
			SchemaName: "otherwise_relogin_days",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "TmpSessions",
			SchemaName: "tmp_sessions",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "FutureAuthToken",
			SchemaName: "future_auth_token",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "User",
			SchemaName: "user",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AuthAuthorization) () {
	if !(.SetupPasswordRequired == false) {
		.Flags.Set(1)
	}
	if !(.OtherwiseReloginDays == 0) {
		.Flags.Set(1)
	}
	if !(.TmpSessions == 0) {
		.Flags.Set(0)
	}
	if !(.FutureAuthToken == nil) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *AuthAuthorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.authorization#2ea2c0d4 as nil")
	}
	.PutID(AuthAuthorizationTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AuthAuthorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.authorization#2ea2c0d4 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode auth.authorization#2ea2c0d4: field flags: %w", )
	}
	if .Flags.Has(1) {
		.PutInt(.OtherwiseReloginDays)
	}
	if .Flags.Has(0) {
		.PutInt(.TmpSessions)
	}
	if .Flags.Has(2) {
		.PutBytes(.FutureAuthToken)
	}
	if .User == nil {
		return fmt.Errorf("unable to encode auth.authorization#2ea2c0d4: field user is nil")
	}
	if  := .User.Encode();  != nil {
		return fmt.Errorf("unable to encode auth.authorization#2ea2c0d4: field user: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AuthAuthorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.authorization#2ea2c0d4 to nil")
	}
	if  := .ConsumeID(AuthAuthorizationTypeID);  != nil {
		return fmt.Errorf("unable to decode auth.authorization#2ea2c0d4: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AuthAuthorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.authorization#2ea2c0d4 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode auth.authorization#2ea2c0d4: field flags: %w", )
		}
	}
	.SetupPasswordRequired = .Flags.Has(1)
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode auth.authorization#2ea2c0d4: field otherwise_relogin_days: %w", )
		}
		.OtherwiseReloginDays = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode auth.authorization#2ea2c0d4: field tmp_sessions: %w", )
		}
		.TmpSessions = 
	}
	if .Flags.Has(2) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode auth.authorization#2ea2c0d4: field future_auth_token: %w", )
		}
		.FutureAuthToken = 
	}
	{
		,  := DecodeUser()
		if  != nil {
			return fmt.Errorf("unable to decode auth.authorization#2ea2c0d4: field user: %w", )
		}
		.User = 
	}
	return nil
}

// SetSetupPasswordRequired sets value of SetupPasswordRequired conditional field.
func ( *AuthAuthorization) ( bool) {
	if  {
		.Flags.Set(1)
		.SetupPasswordRequired = true
	} else {
		.Flags.Unset(1)
		.SetupPasswordRequired = false
	}
}

// GetSetupPasswordRequired returns value of SetupPasswordRequired conditional field.
func ( *AuthAuthorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetOtherwiseReloginDays sets value of OtherwiseReloginDays conditional field.
func ( *AuthAuthorization) ( int) {
	.Flags.Set(1)
	.OtherwiseReloginDays = 
}

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

// SetTmpSessions sets value of TmpSessions conditional field.
func ( *AuthAuthorization) ( int) {
	.Flags.Set(0)
	.TmpSessions = 
}

// GetTmpSessions returns value of TmpSessions conditional field and
// boolean which is true if field was set.
func ( *AuthAuthorization) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .TmpSessions, true
}

// SetFutureAuthToken sets value of FutureAuthToken conditional field.
func ( *AuthAuthorization) ( []byte) {
	.Flags.Set(2)
	.FutureAuthToken = 
}

// GetFutureAuthToken returns value of FutureAuthToken conditional field and
// boolean which is true if field was set.
func ( *AuthAuthorization) () ( []byte,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .FutureAuthToken, true
}

// GetUser returns value of User field.
func ( *AuthAuthorization) () ( UserClass) {
	if  == nil {
		return
	}
	return .User
}

// AuthAuthorizationSignUpRequired represents TL type `auth.authorizationSignUpRequired#44747e9a`.
// An account with this phone number doesn't exist on telegram: the user has to enter
// basic information and sign up¹
//
// Links:
//  1. https://core.telegram.org/api/auth
//
// See https://core.telegram.org/constructor/auth.authorizationSignUpRequired for reference.
type AuthAuthorizationSignUpRequired struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Telegram's terms of service: the user must read and accept the terms of service before
	// signing up to telegram
	//
	// Use SetTermsOfService and GetTermsOfService helpers.
	TermsOfService HelpTermsOfService
}

// AuthAuthorizationSignUpRequiredTypeID is TL type id of AuthAuthorizationSignUpRequired.
const AuthAuthorizationSignUpRequiredTypeID = 0x44747e9a

// construct implements constructor of AuthAuthorizationClass.
func ( AuthAuthorizationSignUpRequired) () AuthAuthorizationClass { return & }

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

	_ AuthAuthorizationClass = &AuthAuthorizationSignUpRequired{}
)

func ( *AuthAuthorizationSignUpRequired) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.TermsOfService.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills AuthAuthorizationSignUpRequired from given interface.
func ( *AuthAuthorizationSignUpRequired) ( interface {
	() ( HelpTermsOfService,  bool)
}) {
	if ,  := .();  {
		.TermsOfService = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *AuthAuthorizationSignUpRequired) () tdp.Type {
	 := tdp.Type{
		Name: "auth.authorizationSignUpRequired",
		ID:   AuthAuthorizationSignUpRequiredTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "TermsOfService",
			SchemaName: "terms_of_service",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AuthAuthorizationSignUpRequired) () {
	if !(.TermsOfService.Zero()) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *AuthAuthorizationSignUpRequired) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.authorizationSignUpRequired#44747e9a as nil")
	}
	.PutID(AuthAuthorizationSignUpRequiredTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AuthAuthorizationSignUpRequired) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.authorizationSignUpRequired#44747e9a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode auth.authorizationSignUpRequired#44747e9a: field flags: %w", )
	}
	if .Flags.Has(0) {
		if  := .TermsOfService.Encode();  != nil {
			return fmt.Errorf("unable to encode auth.authorizationSignUpRequired#44747e9a: field terms_of_service: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AuthAuthorizationSignUpRequired) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.authorizationSignUpRequired#44747e9a to nil")
	}
	if  := .ConsumeID(AuthAuthorizationSignUpRequiredTypeID);  != nil {
		return fmt.Errorf("unable to decode auth.authorizationSignUpRequired#44747e9a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AuthAuthorizationSignUpRequired) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.authorizationSignUpRequired#44747e9a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode auth.authorizationSignUpRequired#44747e9a: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		if  := .TermsOfService.Decode();  != nil {
			return fmt.Errorf("unable to decode auth.authorizationSignUpRequired#44747e9a: field terms_of_service: %w", )
		}
	}
	return nil
}

// SetTermsOfService sets value of TermsOfService conditional field.
func ( *AuthAuthorizationSignUpRequired) ( HelpTermsOfService) {
	.Flags.Set(0)
	.TermsOfService = 
}

// GetTermsOfService returns value of TermsOfService conditional field and
// boolean which is true if field was set.
func ( *AuthAuthorizationSignUpRequired) () ( HelpTermsOfService,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .TermsOfService, true
}

// AuthAuthorizationClassName is schema name of AuthAuthorizationClass.
const AuthAuthorizationClassName = "auth.Authorization"

// AuthAuthorizationClass represents auth.Authorization generic type.
//
// See https://core.telegram.org/type/auth.Authorization for reference.
//
// Example:
//
//	g, err := tg.DecodeAuthAuthorization(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.AuthAuthorization: // auth.authorization#2ea2c0d4
//	case *tg.AuthAuthorizationSignUpRequired: // auth.authorizationSignUpRequired#44747e9a
//	default: panic(v)
//	}
type AuthAuthorizationClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() AuthAuthorizationClass

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

// DecodeAuthAuthorization implements binary de-serialization for AuthAuthorizationClass.
func ( *bin.Buffer) (AuthAuthorizationClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case AuthAuthorizationTypeID:
		// Decoding auth.authorization#2ea2c0d4.
		 := AuthAuthorization{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode AuthAuthorizationClass: %w", )
		}
		return &, nil
	case AuthAuthorizationSignUpRequiredTypeID:
		// Decoding auth.authorizationSignUpRequired#44747e9a.
		 := AuthAuthorizationSignUpRequired{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode AuthAuthorizationClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode AuthAuthorizationClass: %w", bin.NewUnexpectedID())
	}
}

// AuthAuthorization boxes the AuthAuthorizationClass providing a helper.
type AuthAuthorizationBox struct {
	Authorization AuthAuthorizationClass
}

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

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