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

// Folder represents TL type `folder#ff544e65`.
// Folder
//
// See https://core.telegram.org/constructor/folder for reference.
type Folder struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Automatically add new channels to this folder
	AutofillNewBroadcasts bool
	// Automatically add joined new public supergroups to this folder
	AutofillPublicGroups bool
	// Automatically add new private chats to this folder
	AutofillNewCorrespondents bool
	// Folder ID
	ID int
	// Folder title
	Title string
	// Folder picture
	//
	// Use SetPhoto and GetPhoto helpers.
	Photo ChatPhotoClass
}

// FolderTypeID is TL type id of Folder.
const FolderTypeID = 0xff544e65

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

func ( *Folder) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.AutofillNewBroadcasts == false) {
		return false
	}
	if !(.AutofillPublicGroups == false) {
		return false
	}
	if !(.AutofillNewCorrespondents == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Photo == nil) {
		return false
	}

	return true
}

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

// FillFrom fills Folder from given interface.
func ( *Folder) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int)
	() ( string)
	() ( ChatPhotoClass,  bool)
}) {
	.AutofillNewBroadcasts = .()
	.AutofillPublicGroups = .()
	.AutofillNewCorrespondents = .()
	.ID = .()
	.Title = .()
	if ,  := .();  {
		.Photo = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *Folder) () tdp.Type {
	 := tdp.Type{
		Name: "folder",
		ID:   FolderTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "AutofillNewBroadcasts",
			SchemaName: "autofill_new_broadcasts",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "AutofillPublicGroups",
			SchemaName: "autofill_public_groups",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "AutofillNewCorrespondents",
			SchemaName: "autofill_new_correspondents",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Folder) () {
	if !(.AutofillNewBroadcasts == false) {
		.Flags.Set(0)
	}
	if !(.AutofillPublicGroups == false) {
		.Flags.Set(1)
	}
	if !(.AutofillNewCorrespondents == false) {
		.Flags.Set(2)
	}
	if !(.Photo == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *Folder) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode folder#ff544e65 as nil")
	}
	.PutID(FolderTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Folder) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode folder#ff544e65 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode folder#ff544e65: field flags: %w", )
	}
	.PutInt(.ID)
	.PutString(.Title)
	if .Flags.Has(3) {
		if .Photo == nil {
			return fmt.Errorf("unable to encode folder#ff544e65: field photo is nil")
		}
		if  := .Photo.Encode();  != nil {
			return fmt.Errorf("unable to encode folder#ff544e65: field photo: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *Folder) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode folder#ff544e65 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode folder#ff544e65: field flags: %w", )
		}
	}
	.AutofillNewBroadcasts = .Flags.Has(0)
	.AutofillPublicGroups = .Flags.Has(1)
	.AutofillNewCorrespondents = .Flags.Has(2)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode folder#ff544e65: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode folder#ff544e65: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(3) {
		,  := DecodeChatPhoto()
		if  != nil {
			return fmt.Errorf("unable to decode folder#ff544e65: field photo: %w", )
		}
		.Photo = 
	}
	return nil
}

// SetAutofillNewBroadcasts sets value of AutofillNewBroadcasts conditional field.
func ( *Folder) ( bool) {
	if  {
		.Flags.Set(0)
		.AutofillNewBroadcasts = true
	} else {
		.Flags.Unset(0)
		.AutofillNewBroadcasts = false
	}
}

// GetAutofillNewBroadcasts returns value of AutofillNewBroadcasts conditional field.
func ( *Folder) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetAutofillPublicGroups sets value of AutofillPublicGroups conditional field.
func ( *Folder) ( bool) {
	if  {
		.Flags.Set(1)
		.AutofillPublicGroups = true
	} else {
		.Flags.Unset(1)
		.AutofillPublicGroups = false
	}
}

// GetAutofillPublicGroups returns value of AutofillPublicGroups conditional field.
func ( *Folder) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetAutofillNewCorrespondents sets value of AutofillNewCorrespondents conditional field.
func ( *Folder) ( bool) {
	if  {
		.Flags.Set(2)
		.AutofillNewCorrespondents = true
	} else {
		.Flags.Unset(2)
		.AutofillNewCorrespondents = false
	}
}

// GetAutofillNewCorrespondents returns value of AutofillNewCorrespondents conditional field.
func ( *Folder) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetID returns value of ID field.
func ( *Folder) () ( int) {
	if  == nil {
		return
	}
	return .ID
}

// GetTitle returns value of Title field.
func ( *Folder) () ( string) {
	if  == nil {
		return
	}
	return .Title
}

// SetPhoto sets value of Photo conditional field.
func ( *Folder) ( ChatPhotoClass) {
	.Flags.Set(3)
	.Photo = 
}

// GetPhoto returns value of Photo conditional field and
// boolean which is true if field was set.
func ( *Folder) () ( ChatPhotoClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Photo, true
}

// GetPhotoAsNotEmpty returns mapped value of Photo conditional field and
// boolean which is true if field was set.
func ( *Folder) () (*ChatPhoto, bool) {
	if ,  := .GetPhoto();  {
		return .AsNotEmpty()
	}
	return nil, false
}