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

// Theme represents TL type `theme#a00e67d6`.
// Theme
//
// See https://core.telegram.org/constructor/theme for reference.
type Theme struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the current user is the creator of this theme
	Creator bool
	// Whether this is the default theme
	Default bool
	// Whether this theme is meant to be used as a chat themeĀ¹
	//
	// Links:
	//  1) https://telegram.org/blog/chat-themes-interactive-emoji-read-receipts
	ForChat bool
	// Theme ID
	ID int64
	// Theme access hash
	AccessHash int64
	// Unique theme ID
	Slug string
	// Theme name
	Title string
	// Theme
	//
	// Use SetDocument and GetDocument helpers.
	Document DocumentClass
	// Theme settings
	//
	// Use SetSettings and GetSettings helpers.
	Settings []ThemeSettings
	// Theme emoji
	//
	// Use SetEmoticon and GetEmoticon helpers.
	Emoticon string
	// Installation count
	//
	// Use SetInstallsCount and GetInstallsCount helpers.
	InstallsCount int
}

// ThemeTypeID is TL type id of Theme.
const ThemeTypeID = 0xa00e67d6

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

func ( *Theme) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Creator == false) {
		return false
	}
	if !(.Default == false) {
		return false
	}
	if !(.ForChat == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.AccessHash == 0) {
		return false
	}
	if !(.Slug == "") {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Document == nil) {
		return false
	}
	if !(.Settings == nil) {
		return false
	}
	if !(.Emoticon == "") {
		return false
	}
	if !(.InstallsCount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills Theme from given interface.
func ( *Theme) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int64)
	() ( int64)
	() ( string)
	() ( string)
	() ( DocumentClass,  bool)
	() ( []ThemeSettings,  bool)
	() ( string,  bool)
	() ( int,  bool)
}) {
	.Creator = .()
	.Default = .()
	.ForChat = .()
	.ID = .()
	.AccessHash = .()
	.Slug = .()
	.Title = .()
	if ,  := .();  {
		.Document = 
	}

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *Theme) () tdp.Type {
	 := tdp.Type{
		Name: "theme",
		ID:   ThemeTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Creator",
			SchemaName: "creator",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Default",
			SchemaName: "default",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ForChat",
			SchemaName: "for_chat",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
		{
			Name:       "Slug",
			SchemaName: "slug",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Document",
			SchemaName: "document",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Emoticon",
			SchemaName: "emoticon",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "InstallsCount",
			SchemaName: "installs_count",
			Null:       !.Flags.Has(4),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Theme) () {
	if !(.Creator == false) {
		.Flags.Set(0)
	}
	if !(.Default == false) {
		.Flags.Set(1)
	}
	if !(.ForChat == false) {
		.Flags.Set(5)
	}
	if !(.Document == nil) {
		.Flags.Set(2)
	}
	if !(.Settings == nil) {
		.Flags.Set(3)
	}
	if !(.Emoticon == "") {
		.Flags.Set(6)
	}
	if !(.InstallsCount == 0) {
		.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func ( *Theme) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode theme#a00e67d6 as nil")
	}
	.PutID(ThemeTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Theme) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode theme#a00e67d6 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode theme#a00e67d6: field flags: %w", )
	}
	.PutLong(.ID)
	.PutLong(.AccessHash)
	.PutString(.Slug)
	.PutString(.Title)
	if .Flags.Has(2) {
		if .Document == nil {
			return fmt.Errorf("unable to encode theme#a00e67d6: field document is nil")
		}
		if  := .Document.Encode();  != nil {
			return fmt.Errorf("unable to encode theme#a00e67d6: field document: %w", )
		}
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.Settings))
		for ,  := range .Settings {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode theme#a00e67d6: field settings element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(6) {
		.PutString(.Emoticon)
	}
	if .Flags.Has(4) {
		.PutInt(.InstallsCount)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *Theme) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode theme#a00e67d6 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field flags: %w", )
		}
	}
	.Creator = .Flags.Has(0)
	.Default = .Flags.Has(1)
	.ForChat = .Flags.Has(5)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field access_hash: %w", )
		}
		.AccessHash = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field slug: %w", )
		}
		.Slug = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(2) {
		,  := DecodeDocument()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field document: %w", )
		}
		.Document = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field settings: %w", )
		}

		if  > 0 {
			.Settings = make([]ThemeSettings, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  ThemeSettings
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode theme#a00e67d6: field settings: %w", )
			}
			.Settings = append(.Settings, )
		}
	}
	if .Flags.Has(6) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field emoticon: %w", )
		}
		.Emoticon = 
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode theme#a00e67d6: field installs_count: %w", )
		}
		.InstallsCount = 
	}
	return nil
}

// SetCreator sets value of Creator conditional field.
func ( *Theme) ( bool) {
	if  {
		.Flags.Set(0)
		.Creator = true
	} else {
		.Flags.Unset(0)
		.Creator = false
	}
}

// GetCreator returns value of Creator conditional field.
func ( *Theme) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetDefault sets value of Default conditional field.
func ( *Theme) ( bool) {
	if  {
		.Flags.Set(1)
		.Default = true
	} else {
		.Flags.Unset(1)
		.Default = false
	}
}

// GetDefault returns value of Default conditional field.
func ( *Theme) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetForChat sets value of ForChat conditional field.
func ( *Theme) ( bool) {
	if  {
		.Flags.Set(5)
		.ForChat = true
	} else {
		.Flags.Unset(5)
		.ForChat = false
	}
}

// GetForChat returns value of ForChat conditional field.
func ( *Theme) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

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

// GetAccessHash returns value of AccessHash field.
func ( *Theme) () ( int64) {
	if  == nil {
		return
	}
	return .AccessHash
}

// GetSlug returns value of Slug field.
func ( *Theme) () ( string) {
	if  == nil {
		return
	}
	return .Slug
}

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

// SetDocument sets value of Document conditional field.
func ( *Theme) ( DocumentClass) {
	.Flags.Set(2)
	.Document = 
}

// GetDocument returns value of Document conditional field and
// boolean which is true if field was set.
func ( *Theme) () ( DocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Document, true
}

// SetSettings sets value of Settings conditional field.
func ( *Theme) ( []ThemeSettings) {
	.Flags.Set(3)
	.Settings = 
}

// GetSettings returns value of Settings conditional field and
// boolean which is true if field was set.
func ( *Theme) () ( []ThemeSettings,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Settings, true
}

// SetEmoticon sets value of Emoticon conditional field.
func ( *Theme) ( string) {
	.Flags.Set(6)
	.Emoticon = 
}

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

// SetInstallsCount sets value of InstallsCount conditional field.
func ( *Theme) ( int) {
	.Flags.Set(4)
	.InstallsCount = 
}

// GetInstallsCount returns value of InstallsCount conditional field and
// boolean which is true if field was set.
func ( *Theme) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .InstallsCount, true
}

// GetDocumentAsNotEmpty returns mapped value of Document conditional field and
// boolean which is true if field was set.
func ( *Theme) () (*Document, bool) {
	if ,  := .GetDocument();  {
		return .AsNotEmpty()
	}
	return nil, false
}