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

// AccountSaveAutoSaveSettingsRequest represents TL type `account.saveAutoSaveSettings#d69b8361`.
// Modify autosave settings
//
// See https://core.telegram.org/method/account.saveAutoSaveSettings for reference.
type AccountSaveAutoSaveSettingsRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the new settings should affect all private chats
	Users bool
	// Whether the new settings should affect all groups
	Chats bool
	// Whether the new settings should affect all channelsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/api/channel
	Broadcasts bool
	// Whether the new settings should affect a specific peer
	//
	// Use SetPeer and GetPeer helpers.
	Peer InputPeerClass
	// The new autosave settings
	Settings AutoSaveSettings
}

// AccountSaveAutoSaveSettingsRequestTypeID is TL type id of AccountSaveAutoSaveSettingsRequest.
const AccountSaveAutoSaveSettingsRequestTypeID = 0xd69b8361

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

func ( *AccountSaveAutoSaveSettingsRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Users == false) {
		return false
	}
	if !(.Chats == false) {
		return false
	}
	if !(.Broadcasts == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Settings.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills AccountSaveAutoSaveSettingsRequest from given interface.
func ( *AccountSaveAutoSaveSettingsRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( InputPeerClass,  bool)
	() ( AutoSaveSettings)
}) {
	.Users = .()
	.Chats = .()
	.Broadcasts = .()
	if ,  := .();  {
		.Peer = 
	}

	.Settings = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *AccountSaveAutoSaveSettingsRequest) () tdp.Type {
	 := tdp.Type{
		Name: "account.saveAutoSaveSettings",
		ID:   AccountSaveAutoSaveSettingsRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Users",
			SchemaName: "users",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Broadcasts",
			SchemaName: "broadcasts",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AccountSaveAutoSaveSettingsRequest) () {
	if !(.Users == false) {
		.Flags.Set(0)
	}
	if !(.Chats == false) {
		.Flags.Set(1)
	}
	if !(.Broadcasts == false) {
		.Flags.Set(2)
	}
	if !(.Peer == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *AccountSaveAutoSaveSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.saveAutoSaveSettings#d69b8361 as nil")
	}
	.PutID(AccountSaveAutoSaveSettingsRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountSaveAutoSaveSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.saveAutoSaveSettings#d69b8361 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode account.saveAutoSaveSettings#d69b8361: field flags: %w", )
	}
	if .Flags.Has(3) {
		if .Peer == nil {
			return fmt.Errorf("unable to encode account.saveAutoSaveSettings#d69b8361: field peer is nil")
		}
		if  := .Peer.Encode();  != nil {
			return fmt.Errorf("unable to encode account.saveAutoSaveSettings#d69b8361: field peer: %w", )
		}
	}
	if  := .Settings.Encode();  != nil {
		return fmt.Errorf("unable to encode account.saveAutoSaveSettings#d69b8361: field settings: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *AccountSaveAutoSaveSettingsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.saveAutoSaveSettings#d69b8361 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode account.saveAutoSaveSettings#d69b8361: field flags: %w", )
		}
	}
	.Users = .Flags.Has(0)
	.Chats = .Flags.Has(1)
	.Broadcasts = .Flags.Has(2)
	if .Flags.Has(3) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode account.saveAutoSaveSettings#d69b8361: field peer: %w", )
		}
		.Peer = 
	}
	{
		if  := .Settings.Decode();  != nil {
			return fmt.Errorf("unable to decode account.saveAutoSaveSettings#d69b8361: field settings: %w", )
		}
	}
	return nil
}

// SetUsers sets value of Users conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Users = true
	} else {
		.Flags.Unset(0)
		.Users = false
	}
}

// GetUsers returns value of Users conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetChats sets value of Chats conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.Chats = true
	} else {
		.Flags.Unset(1)
		.Chats = false
	}
}

// GetChats returns value of Chats conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetBroadcasts sets value of Broadcasts conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.Broadcasts = true
	} else {
		.Flags.Unset(2)
		.Broadcasts = false
	}
}

// GetBroadcasts returns value of Broadcasts conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetPeer sets value of Peer conditional field.
func ( *AccountSaveAutoSaveSettingsRequest) ( InputPeerClass) {
	.Flags.Set(3)
	.Peer = 
}

// GetPeer returns value of Peer conditional field and
// boolean which is true if field was set.
func ( *AccountSaveAutoSaveSettingsRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Peer, true
}

// GetSettings returns value of Settings field.
func ( *AccountSaveAutoSaveSettingsRequest) () ( AutoSaveSettings) {
	if  == nil {
		return
	}
	return .Settings
}

// AccountSaveAutoSaveSettings invokes method account.saveAutoSaveSettings#d69b8361 returning error if any.
// Modify autosave settings
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/account.saveAutoSaveSettings for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *AccountSaveAutoSaveSettingsRequest) (bool, error) {
	var  BoolBox

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