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

// AccountChangeAuthorizationSettingsRequest represents TL type `account.changeAuthorizationSettings#40f48462`.
// Change settings related to a session.
//
// See https://core.telegram.org/method/account.changeAuthorizationSettings for reference.
type AccountChangeAuthorizationSettingsRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, confirms a newly logged in session »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/auth#confirming-login
	Confirmed bool
	// Session ID from the authorization¹ constructor, fetchable using account
	// getAuthorizations²
	//
	// Links:
	//  1) https://core.telegram.org/constructor/authorization
	//  2) https://core.telegram.org/method/account.getAuthorizations
	Hash int64
	// Whether to enable or disable receiving encrypted chats: if the flag is not set, the
	// previous setting is not changed
	//
	// Use SetEncryptedRequestsDisabled and GetEncryptedRequestsDisabled helpers.
	EncryptedRequestsDisabled bool
	// Whether to enable or disable receiving calls: if the flag is not set, the previous
	// setting is not changed
	//
	// Use SetCallRequestsDisabled and GetCallRequestsDisabled helpers.
	CallRequestsDisabled bool
}

// AccountChangeAuthorizationSettingsRequestTypeID is TL type id of AccountChangeAuthorizationSettingsRequest.
const AccountChangeAuthorizationSettingsRequestTypeID = 0x40f48462

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

func ( *AccountChangeAuthorizationSettingsRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Confirmed == false) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}
	if !(.EncryptedRequestsDisabled == false) {
		return false
	}
	if !(.CallRequestsDisabled == false) {
		return false
	}

	return true
}

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

// FillFrom fills AccountChangeAuthorizationSettingsRequest from given interface.
func ( *AccountChangeAuthorizationSettingsRequest) ( interface {
	() ( bool)
	() ( int64)
	() ( bool,  bool)
	() ( bool,  bool)
}) {
	.Confirmed = .()
	.Hash = .()
	if ,  := .();  {
		.EncryptedRequestsDisabled = 
	}

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

}

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

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

// TypeInfo returns info about TL type.
func ( *AccountChangeAuthorizationSettingsRequest) () tdp.Type {
	 := tdp.Type{
		Name: "account.changeAuthorizationSettings",
		ID:   AccountChangeAuthorizationSettingsRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Confirmed",
			SchemaName: "confirmed",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
		{
			Name:       "EncryptedRequestsDisabled",
			SchemaName: "encrypted_requests_disabled",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "CallRequestsDisabled",
			SchemaName: "call_requests_disabled",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AccountChangeAuthorizationSettingsRequest) () {
	if !(.Confirmed == false) {
		.Flags.Set(3)
	}
	if !(.EncryptedRequestsDisabled == false) {
		.Flags.Set(0)
	}
	if !(.CallRequestsDisabled == false) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *AccountChangeAuthorizationSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.changeAuthorizationSettings#40f48462 as nil")
	}
	.PutID(AccountChangeAuthorizationSettingsRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountChangeAuthorizationSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.changeAuthorizationSettings#40f48462 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode account.changeAuthorizationSettings#40f48462: field flags: %w", )
	}
	.PutLong(.Hash)
	if .Flags.Has(0) {
		.PutBool(.EncryptedRequestsDisabled)
	}
	if .Flags.Has(1) {
		.PutBool(.CallRequestsDisabled)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AccountChangeAuthorizationSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.changeAuthorizationSettings#40f48462 to nil")
	}
	if  := .ConsumeID(AccountChangeAuthorizationSettingsRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode account.changeAuthorizationSettings#40f48462: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AccountChangeAuthorizationSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.changeAuthorizationSettings#40f48462 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode account.changeAuthorizationSettings#40f48462: field flags: %w", )
		}
	}
	.Confirmed = .Flags.Has(3)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode account.changeAuthorizationSettings#40f48462: field hash: %w", )
		}
		.Hash = 
	}
	if .Flags.Has(0) {
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode account.changeAuthorizationSettings#40f48462: field encrypted_requests_disabled: %w", )
		}
		.EncryptedRequestsDisabled = 
	}
	if .Flags.Has(1) {
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode account.changeAuthorizationSettings#40f48462: field call_requests_disabled: %w", )
		}
		.CallRequestsDisabled = 
	}
	return nil
}

// SetConfirmed sets value of Confirmed conditional field.
func ( *AccountChangeAuthorizationSettingsRequest) ( bool) {
	if  {
		.Flags.Set(3)
		.Confirmed = true
	} else {
		.Flags.Unset(3)
		.Confirmed = false
	}
}

// GetConfirmed returns value of Confirmed conditional field.
func ( *AccountChangeAuthorizationSettingsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// GetHash returns value of Hash field.
func ( *AccountChangeAuthorizationSettingsRequest) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}

// SetEncryptedRequestsDisabled sets value of EncryptedRequestsDisabled conditional field.
func ( *AccountChangeAuthorizationSettingsRequest) ( bool) {
	.Flags.Set(0)
	.EncryptedRequestsDisabled = 
}

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

// SetCallRequestsDisabled sets value of CallRequestsDisabled conditional field.
func ( *AccountChangeAuthorizationSettingsRequest) ( bool) {
	.Flags.Set(1)
	.CallRequestsDisabled = 
}

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

// AccountChangeAuthorizationSettings invokes method account.changeAuthorizationSettings#40f48462 returning error if any.
// Change settings related to a session.
//
// Possible errors:
//
//	400 HASH_INVALID: The provided hash is invalid.
//
// See https://core.telegram.org/method/account.changeAuthorizationSettings for reference.
func ( *Client) ( context.Context,  *AccountChangeAuthorizationSettingsRequest) (bool, error) {
	var  BoolBox

	if  := .rpc.Invoke(, , &);  != nil {
		return false, 
	}
	,  := .Bool.(*BoolTrue)
	return , nil
}