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

// AccountPassword represents TL type `account.password#957b50fb`.
// Configuration for two-factor authorization
//
// See https://core.telegram.org/constructor/account.password for reference.
type AccountPassword struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the user has a recovery method configured
	HasRecovery bool
	// Whether telegram passport¹ is enabled
	//
	// Links:
	//  1) https://core.telegram.org/passport
	HasSecureValues bool
	// Whether the user has a password
	HasPassword bool
	// The KDF algorithm for SRP two-factor authentication¹ of the current password
	//
	// Links:
	//  1) https://core.telegram.org/api/srp
	//
	// Use SetCurrentAlgo and GetCurrentAlgo helpers.
	CurrentAlgo PasswordKdfAlgoClass
	// Srp B param for SRP authorization¹
	//
	// Links:
	//  1) https://core.telegram.org/api/srp
	//
	// Use SetSRPB and GetSRPB helpers.
	SRPB []byte
	// Srp ID param for SRP authorization¹
	//
	// Links:
	//  1) https://core.telegram.org/api/srp
	//
	// Use SetSRPID and GetSRPID helpers.
	SRPID int64
	// Text hint for the password
	//
	// Use SetHint and GetHint helpers.
	Hint string
	// A password recovery email¹ with the specified pattern² is still awaiting
	// verification
	//
	// Links:
	//  1) https://core.telegram.org/api/srp#email-verification
	//  2) https://core.telegram.org/api/pattern
	//
	// Use SetEmailUnconfirmedPattern and GetEmailUnconfirmedPattern helpers.
	EmailUnconfirmedPattern string
	// The KDF algorithm for SRP two-factor authentication¹ to use when creating new
	// passwords
	//
	// Links:
	//  1) https://core.telegram.org/api/srp
	NewAlgo PasswordKdfAlgoClass
	// The KDF algorithm for telegram passport¹
	//
	// Links:
	//  1) https://core.telegram.org/passport
	NewSecureAlgo SecurePasswordKdfAlgoClass
	// Secure random string
	SecureRandom []byte
	// The 2FA password will be automatically removed at this date, unless the user cancels
	// the operation
	//
	// Use SetPendingResetDate and GetPendingResetDate helpers.
	PendingResetDate int
	// A verified login email with the specified pattern¹ is configured
	//
	// Links:
	//  1) https://core.telegram.org/api/pattern
	//
	// Use SetLoginEmailPattern and GetLoginEmailPattern helpers.
	LoginEmailPattern string
}

// AccountPasswordTypeID is TL type id of AccountPassword.
const AccountPasswordTypeID = 0x957b50fb

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

func ( *AccountPassword) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasRecovery == false) {
		return false
	}
	if !(.HasSecureValues == false) {
		return false
	}
	if !(.HasPassword == false) {
		return false
	}
	if !(.CurrentAlgo == nil) {
		return false
	}
	if !(.SRPB == nil) {
		return false
	}
	if !(.SRPID == 0) {
		return false
	}
	if !(.Hint == "") {
		return false
	}
	if !(.EmailUnconfirmedPattern == "") {
		return false
	}
	if !(.NewAlgo == nil) {
		return false
	}
	if !(.NewSecureAlgo == nil) {
		return false
	}
	if !(.SecureRandom == nil) {
		return false
	}
	if !(.PendingResetDate == 0) {
		return false
	}
	if !(.LoginEmailPattern == "") {
		return false
	}

	return true
}

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

// FillFrom fills AccountPassword from given interface.
func ( *AccountPassword) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( PasswordKdfAlgoClass,  bool)
	() ( []byte,  bool)
	() ( int64,  bool)
	() ( string,  bool)
	() ( string,  bool)
	() ( PasswordKdfAlgoClass)
	() ( SecurePasswordKdfAlgoClass)
	() ( []byte)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.HasRecovery = .()
	.HasSecureValues = .()
	.HasPassword = .()
	if ,  := .();  {
		.CurrentAlgo = 
	}

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

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

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

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

	.NewAlgo = .()
	.NewSecureAlgo = .()
	.SecureRandom = .()
	if ,  := .();  {
		.PendingResetDate = 
	}

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

}

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

// TypeName returns name of type in TL schema.
func (*AccountPassword) () string {
	return "account.password"
}

// TypeInfo returns info about TL type.
func ( *AccountPassword) () tdp.Type {
	 := tdp.Type{
		Name: "account.password",
		ID:   AccountPasswordTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasRecovery",
			SchemaName: "has_recovery",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "HasSecureValues",
			SchemaName: "has_secure_values",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "HasPassword",
			SchemaName: "has_password",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "CurrentAlgo",
			SchemaName: "current_algo",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "SRPB",
			SchemaName: "srp_B",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "SRPID",
			SchemaName: "srp_id",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Hint",
			SchemaName: "hint",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "EmailUnconfirmedPattern",
			SchemaName: "email_unconfirmed_pattern",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "NewAlgo",
			SchemaName: "new_algo",
		},
		{
			Name:       "NewSecureAlgo",
			SchemaName: "new_secure_algo",
		},
		{
			Name:       "SecureRandom",
			SchemaName: "secure_random",
		},
		{
			Name:       "PendingResetDate",
			SchemaName: "pending_reset_date",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "LoginEmailPattern",
			SchemaName: "login_email_pattern",
			Null:       !.Flags.Has(6),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AccountPassword) () {
	if !(.HasRecovery == false) {
		.Flags.Set(0)
	}
	if !(.HasSecureValues == false) {
		.Flags.Set(1)
	}
	if !(.HasPassword == false) {
		.Flags.Set(2)
	}
	if !(.CurrentAlgo == nil) {
		.Flags.Set(2)
	}
	if !(.SRPB == nil) {
		.Flags.Set(2)
	}
	if !(.SRPID == 0) {
		.Flags.Set(2)
	}
	if !(.Hint == "") {
		.Flags.Set(3)
	}
	if !(.EmailUnconfirmedPattern == "") {
		.Flags.Set(4)
	}
	if !(.PendingResetDate == 0) {
		.Flags.Set(5)
	}
	if !(.LoginEmailPattern == "") {
		.Flags.Set(6)
	}
}

// Encode implements bin.Encoder.
func ( *AccountPassword) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.password#957b50fb as nil")
	}
	.PutID(AccountPasswordTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountPassword) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.password#957b50fb as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode account.password#957b50fb: field flags: %w", )
	}
	if .Flags.Has(2) {
		if .CurrentAlgo == nil {
			return fmt.Errorf("unable to encode account.password#957b50fb: field current_algo is nil")
		}
		if  := .CurrentAlgo.Encode();  != nil {
			return fmt.Errorf("unable to encode account.password#957b50fb: field current_algo: %w", )
		}
	}
	if .Flags.Has(2) {
		.PutBytes(.SRPB)
	}
	if .Flags.Has(2) {
		.PutLong(.SRPID)
	}
	if .Flags.Has(3) {
		.PutString(.Hint)
	}
	if .Flags.Has(4) {
		.PutString(.EmailUnconfirmedPattern)
	}
	if .NewAlgo == nil {
		return fmt.Errorf("unable to encode account.password#957b50fb: field new_algo is nil")
	}
	if  := .NewAlgo.Encode();  != nil {
		return fmt.Errorf("unable to encode account.password#957b50fb: field new_algo: %w", )
	}
	if .NewSecureAlgo == nil {
		return fmt.Errorf("unable to encode account.password#957b50fb: field new_secure_algo is nil")
	}
	if  := .NewSecureAlgo.Encode();  != nil {
		return fmt.Errorf("unable to encode account.password#957b50fb: field new_secure_algo: %w", )
	}
	.PutBytes(.SecureRandom)
	if .Flags.Has(5) {
		.PutInt(.PendingResetDate)
	}
	if .Flags.Has(6) {
		.PutString(.LoginEmailPattern)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AccountPassword) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.password#957b50fb to nil")
	}
	if  := .ConsumeID(AccountPasswordTypeID);  != nil {
		return fmt.Errorf("unable to decode account.password#957b50fb: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AccountPassword) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.password#957b50fb to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field flags: %w", )
		}
	}
	.HasRecovery = .Flags.Has(0)
	.HasSecureValues = .Flags.Has(1)
	.HasPassword = .Flags.Has(2)
	if .Flags.Has(2) {
		,  := DecodePasswordKdfAlgo()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field current_algo: %w", )
		}
		.CurrentAlgo = 
	}
	if .Flags.Has(2) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field srp_B: %w", )
		}
		.SRPB = 
	}
	if .Flags.Has(2) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field srp_id: %w", )
		}
		.SRPID = 
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field hint: %w", )
		}
		.Hint = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field email_unconfirmed_pattern: %w", )
		}
		.EmailUnconfirmedPattern = 
	}
	{
		,  := DecodePasswordKdfAlgo()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field new_algo: %w", )
		}
		.NewAlgo = 
	}
	{
		,  := DecodeSecurePasswordKdfAlgo()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field new_secure_algo: %w", )
		}
		.NewSecureAlgo = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field secure_random: %w", )
		}
		.SecureRandom = 
	}
	if .Flags.Has(5) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field pending_reset_date: %w", )
		}
		.PendingResetDate = 
	}
	if .Flags.Has(6) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.password#957b50fb: field login_email_pattern: %w", )
		}
		.LoginEmailPattern = 
	}
	return nil
}

// SetHasRecovery sets value of HasRecovery conditional field.
func ( *AccountPassword) ( bool) {
	if  {
		.Flags.Set(0)
		.HasRecovery = true
	} else {
		.Flags.Unset(0)
		.HasRecovery = false
	}
}

// GetHasRecovery returns value of HasRecovery conditional field.
func ( *AccountPassword) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetHasSecureValues sets value of HasSecureValues conditional field.
func ( *AccountPassword) ( bool) {
	if  {
		.Flags.Set(1)
		.HasSecureValues = true
	} else {
		.Flags.Unset(1)
		.HasSecureValues = false
	}
}

// GetHasSecureValues returns value of HasSecureValues conditional field.
func ( *AccountPassword) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetHasPassword sets value of HasPassword conditional field.
func ( *AccountPassword) ( bool) {
	if  {
		.Flags.Set(2)
		.HasPassword = true
	} else {
		.Flags.Unset(2)
		.HasPassword = false
	}
}

// GetHasPassword returns value of HasPassword conditional field.
func ( *AccountPassword) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetCurrentAlgo sets value of CurrentAlgo conditional field.
func ( *AccountPassword) ( PasswordKdfAlgoClass) {
	.Flags.Set(2)
	.CurrentAlgo = 
}

// GetCurrentAlgo returns value of CurrentAlgo conditional field and
// boolean which is true if field was set.
func ( *AccountPassword) () ( PasswordKdfAlgoClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .CurrentAlgo, true
}

// SetSRPB sets value of SRPB conditional field.
func ( *AccountPassword) ( []byte) {
	.Flags.Set(2)
	.SRPB = 
}

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

// SetSRPID sets value of SRPID conditional field.
func ( *AccountPassword) ( int64) {
	.Flags.Set(2)
	.SRPID = 
}

// GetSRPID returns value of SRPID conditional field and
// boolean which is true if field was set.
func ( *AccountPassword) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .SRPID, true
}

// SetHint sets value of Hint conditional field.
func ( *AccountPassword) ( string) {
	.Flags.Set(3)
	.Hint = 
}

// GetHint returns value of Hint conditional field and
// boolean which is true if field was set.
func ( *AccountPassword) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Hint, true
}

// SetEmailUnconfirmedPattern sets value of EmailUnconfirmedPattern conditional field.
func ( *AccountPassword) ( string) {
	.Flags.Set(4)
	.EmailUnconfirmedPattern = 
}

// GetEmailUnconfirmedPattern returns value of EmailUnconfirmedPattern conditional field and
// boolean which is true if field was set.
func ( *AccountPassword) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .EmailUnconfirmedPattern, true
}

// GetNewAlgo returns value of NewAlgo field.
func ( *AccountPassword) () ( PasswordKdfAlgoClass) {
	if  == nil {
		return
	}
	return .NewAlgo
}

// GetNewSecureAlgo returns value of NewSecureAlgo field.
func ( *AccountPassword) () ( SecurePasswordKdfAlgoClass) {
	if  == nil {
		return
	}
	return .NewSecureAlgo
}

// GetSecureRandom returns value of SecureRandom field.
func ( *AccountPassword) () ( []byte) {
	if  == nil {
		return
	}
	return .SecureRandom
}

// SetPendingResetDate sets value of PendingResetDate conditional field.
func ( *AccountPassword) ( int) {
	.Flags.Set(5)
	.PendingResetDate = 
}

// GetPendingResetDate returns value of PendingResetDate conditional field and
// boolean which is true if field was set.
func ( *AccountPassword) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .PendingResetDate, true
}

// SetLoginEmailPattern sets value of LoginEmailPattern conditional field.
func ( *AccountPassword) ( string) {
	.Flags.Set(6)
	.LoginEmailPattern = 
}

// GetLoginEmailPattern returns value of LoginEmailPattern conditional field and
// boolean which is true if field was set.
func ( *AccountPassword) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .LoginEmailPattern, true
}