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

// CodeSettings represents TL type `codeSettings#ad253d78`.
// Settings used by telegram servers for sending the confirm code.
// Example implementations: telegram for android¹, tdlib².
//
// Links:
//  1. https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java
//  2. https://github.com/tdlib/td/tree/master/td/telegram/SendCodeHelper.cpp
//
// See https://core.telegram.org/constructor/codeSettings for reference.
type CodeSettings struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether to allow phone verification via phone calls¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/auth
	AllowFlashcall bool
	// Pass true if the phone number is used on the current device. Ignored if
	// allow_flashcall is not set.
	CurrentNumber bool
	// If a token that will be included in eventually sent SMSs is required: required in
	// newer versions of android, to use the android SMS receiver APIs¹
	//
	// Links:
	//  1) https://developers.google.com/identity/sms-retriever/overview
	AllowAppHash bool
	// Whether this device supports receiving the code using the auth.codeTypeMissedCall¹
	// method
	//
	// Links:
	//  1) https://core.telegram.org/constructor/auth.codeTypeMissedCall
	AllowMissedCall bool
	// Whether Firebase auth is supported
	AllowFirebase bool
	// Previously stored future auth tokens, see the documentation for more info »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/auth#future-auth-tokens
	//
	// Use SetLogoutTokens and GetLogoutTokens helpers.
	LogoutTokens [][]byte
	// Used only by official iOS apps for Firebase auth: device token for apple push.
	//
	// Use SetToken and GetToken helpers.
	Token string
	// Used only by official iOS apps for firebase auth: whether a sandbox-certificate will
	// be used during transmission of the push notification.
	//
	// Use SetAppSandbox and GetAppSandbox helpers.
	AppSandbox bool
}

// CodeSettingsTypeID is TL type id of CodeSettings.
const CodeSettingsTypeID = 0xad253d78

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

func ( *CodeSettings) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.AllowFlashcall == false) {
		return false
	}
	if !(.CurrentNumber == false) {
		return false
	}
	if !(.AllowAppHash == false) {
		return false
	}
	if !(.AllowMissedCall == false) {
		return false
	}
	if !(.AllowFirebase == false) {
		return false
	}
	if !(.LogoutTokens == nil) {
		return false
	}
	if !(.Token == "") {
		return false
	}
	if !(.AppSandbox == false) {
		return false
	}

	return true
}

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

// FillFrom fills CodeSettings from given interface.
func ( *CodeSettings) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( [][]byte,  bool)
	() ( string,  bool)
	() ( bool,  bool)
}) {
	.AllowFlashcall = .()
	.CurrentNumber = .()
	.AllowAppHash = .()
	.AllowMissedCall = .()
	.AllowFirebase = .()
	if ,  := .();  {
		.LogoutTokens = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *CodeSettings) () tdp.Type {
	 := tdp.Type{
		Name: "codeSettings",
		ID:   CodeSettingsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "AllowFlashcall",
			SchemaName: "allow_flashcall",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "CurrentNumber",
			SchemaName: "current_number",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "AllowAppHash",
			SchemaName: "allow_app_hash",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "AllowMissedCall",
			SchemaName: "allow_missed_call",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "AllowFirebase",
			SchemaName: "allow_firebase",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "LogoutTokens",
			SchemaName: "logout_tokens",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "Token",
			SchemaName: "token",
			Null:       !.Flags.Has(8),
		},
		{
			Name:       "AppSandbox",
			SchemaName: "app_sandbox",
			Null:       !.Flags.Has(8),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *CodeSettings) () {
	if !(.AllowFlashcall == false) {
		.Flags.Set(0)
	}
	if !(.CurrentNumber == false) {
		.Flags.Set(1)
	}
	if !(.AllowAppHash == false) {
		.Flags.Set(4)
	}
	if !(.AllowMissedCall == false) {
		.Flags.Set(5)
	}
	if !(.AllowFirebase == false) {
		.Flags.Set(7)
	}
	if !(.LogoutTokens == nil) {
		.Flags.Set(6)
	}
	if !(.Token == "") {
		.Flags.Set(8)
	}
	if !(.AppSandbox == false) {
		.Flags.Set(8)
	}
}

// Encode implements bin.Encoder.
func ( *CodeSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode codeSettings#ad253d78 as nil")
	}
	.PutID(CodeSettingsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *CodeSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode codeSettings#ad253d78 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode codeSettings#ad253d78: field flags: %w", )
	}
	if .Flags.Has(6) {
		.PutVectorHeader(len(.LogoutTokens))
		for ,  := range .LogoutTokens {
			.PutBytes()
		}
	}
	if .Flags.Has(8) {
		.PutString(.Token)
	}
	if .Flags.Has(8) {
		.PutBool(.AppSandbox)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *CodeSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode codeSettings#ad253d78 to nil")
	}
	if  := .ConsumeID(CodeSettingsTypeID);  != nil {
		return fmt.Errorf("unable to decode codeSettings#ad253d78: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *CodeSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode codeSettings#ad253d78 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode codeSettings#ad253d78: field flags: %w", )
		}
	}
	.AllowFlashcall = .Flags.Has(0)
	.CurrentNumber = .Flags.Has(1)
	.AllowAppHash = .Flags.Has(4)
	.AllowMissedCall = .Flags.Has(5)
	.AllowFirebase = .Flags.Has(7)
	if .Flags.Has(6) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode codeSettings#ad253d78: field logout_tokens: %w", )
		}

		if  > 0 {
			.LogoutTokens = make([][]byte, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Bytes()
			if  != nil {
				return fmt.Errorf("unable to decode codeSettings#ad253d78: field logout_tokens: %w", )
			}
			.LogoutTokens = append(.LogoutTokens, )
		}
	}
	if .Flags.Has(8) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode codeSettings#ad253d78: field token: %w", )
		}
		.Token = 
	}
	if .Flags.Has(8) {
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode codeSettings#ad253d78: field app_sandbox: %w", )
		}
		.AppSandbox = 
	}
	return nil
}

// SetAllowFlashcall sets value of AllowFlashcall conditional field.
func ( *CodeSettings) ( bool) {
	if  {
		.Flags.Set(0)
		.AllowFlashcall = true
	} else {
		.Flags.Unset(0)
		.AllowFlashcall = false
	}
}

// GetAllowFlashcall returns value of AllowFlashcall conditional field.
func ( *CodeSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetCurrentNumber sets value of CurrentNumber conditional field.
func ( *CodeSettings) ( bool) {
	if  {
		.Flags.Set(1)
		.CurrentNumber = true
	} else {
		.Flags.Unset(1)
		.CurrentNumber = false
	}
}

// GetCurrentNumber returns value of CurrentNumber conditional field.
func ( *CodeSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetAllowAppHash sets value of AllowAppHash conditional field.
func ( *CodeSettings) ( bool) {
	if  {
		.Flags.Set(4)
		.AllowAppHash = true
	} else {
		.Flags.Unset(4)
		.AllowAppHash = false
	}
}

// GetAllowAppHash returns value of AllowAppHash conditional field.
func ( *CodeSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetAllowMissedCall sets value of AllowMissedCall conditional field.
func ( *CodeSettings) ( bool) {
	if  {
		.Flags.Set(5)
		.AllowMissedCall = true
	} else {
		.Flags.Unset(5)
		.AllowMissedCall = false
	}
}

// GetAllowMissedCall returns value of AllowMissedCall conditional field.
func ( *CodeSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetAllowFirebase sets value of AllowFirebase conditional field.
func ( *CodeSettings) ( bool) {
	if  {
		.Flags.Set(7)
		.AllowFirebase = true
	} else {
		.Flags.Unset(7)
		.AllowFirebase = false
	}
}

// GetAllowFirebase returns value of AllowFirebase conditional field.
func ( *CodeSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

// SetLogoutTokens sets value of LogoutTokens conditional field.
func ( *CodeSettings) ( [][]byte) {
	.Flags.Set(6)
	.LogoutTokens = 
}

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

// SetToken sets value of Token conditional field.
func ( *CodeSettings) ( string) {
	.Flags.Set(8)
	.Token = 
}

// GetToken returns value of Token conditional field and
// boolean which is true if field was set.
func ( *CodeSettings) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(8) {
		return , false
	}
	return .Token, true
}

// SetAppSandbox sets value of AppSandbox conditional field.
func ( *CodeSettings) ( bool) {
	.Flags.Set(8)
	.AppSandbox = 
}

// GetAppSandbox returns value of AppSandbox conditional field and
// boolean which is true if field was set.
func ( *CodeSettings) () ( bool,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(8) {
		return , false
	}
	return .AppSandbox, true
}