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

// AutoSaveSettings represents TL type `autoSaveSettings#c84834ce`.
// Media autosave settings
//
// See https://core.telegram.org/constructor/autoSaveSettings for reference.
type AutoSaveSettings struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether photos should be autosaved to the gallery.
	Photos bool
	// Whether videos should be autosaved to the gallery.
	Videos bool
	// If set, specifies a size limit for autosavable videos
	//
	// Use SetVideoMaxSize and GetVideoMaxSize helpers.
	VideoMaxSize int64
}

// AutoSaveSettingsTypeID is TL type id of AutoSaveSettings.
const AutoSaveSettingsTypeID = 0xc84834ce

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

func ( *AutoSaveSettings) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Photos == false) {
		return false
	}
	if !(.Videos == false) {
		return false
	}
	if !(.VideoMaxSize == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AutoSaveSettings from given interface.
func ( *AutoSaveSettings) ( interface {
	() ( bool)
	() ( bool)
	() ( int64,  bool)
}) {
	.Photos = .()
	.Videos = .()
	if ,  := .();  {
		.VideoMaxSize = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *AutoSaveSettings) () tdp.Type {
	 := tdp.Type{
		Name: "autoSaveSettings",
		ID:   AutoSaveSettingsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Photos",
			SchemaName: "photos",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Videos",
			SchemaName: "videos",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "VideoMaxSize",
			SchemaName: "video_max_size",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AutoSaveSettings) () {
	if !(.Photos == false) {
		.Flags.Set(0)
	}
	if !(.Videos == false) {
		.Flags.Set(1)
	}
	if !(.VideoMaxSize == 0) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *AutoSaveSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode autoSaveSettings#c84834ce as nil")
	}
	.PutID(AutoSaveSettingsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AutoSaveSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode autoSaveSettings#c84834ce as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode autoSaveSettings#c84834ce: field flags: %w", )
	}
	if .Flags.Has(2) {
		.PutLong(.VideoMaxSize)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *AutoSaveSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode autoSaveSettings#c84834ce to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode autoSaveSettings#c84834ce: field flags: %w", )
		}
	}
	.Photos = .Flags.Has(0)
	.Videos = .Flags.Has(1)
	if .Flags.Has(2) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode autoSaveSettings#c84834ce: field video_max_size: %w", )
		}
		.VideoMaxSize = 
	}
	return nil
}

// SetPhotos sets value of Photos conditional field.
func ( *AutoSaveSettings) ( bool) {
	if  {
		.Flags.Set(0)
		.Photos = true
	} else {
		.Flags.Unset(0)
		.Photos = false
	}
}

// GetPhotos returns value of Photos conditional field.
func ( *AutoSaveSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetVideos sets value of Videos conditional field.
func ( *AutoSaveSettings) ( bool) {
	if  {
		.Flags.Set(1)
		.Videos = true
	} else {
		.Flags.Unset(1)
		.Videos = false
	}
}

// GetVideos returns value of Videos conditional field.
func ( *AutoSaveSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetVideoMaxSize sets value of VideoMaxSize conditional field.
func ( *AutoSaveSettings) ( int64) {
	.Flags.Set(2)
	.VideoMaxSize = 
}

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