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

// AccountUpdateThemeRequest represents TL type `account.updateTheme#2bf40ccc`.
// Update theme
//
// See https://core.telegram.org/method/account.updateTheme for reference.
type AccountUpdateThemeRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Theme format, a string that identifies the theming engines supported by the client
	Format string
	// Theme to update
	Theme InputThemeClass
	// Unique theme ID
	//
	// Use SetSlug and GetSlug helpers.
	Slug string
	// Theme name
	//
	// Use SetTitle and GetTitle helpers.
	Title string
	// Theme file
	//
	// Use SetDocument and GetDocument helpers.
	Document InputDocumentClass
	// Theme settings
	//
	// Use SetSettings and GetSettings helpers.
	Settings []InputThemeSettings
}

// AccountUpdateThemeRequestTypeID is TL type id of AccountUpdateThemeRequest.
const AccountUpdateThemeRequestTypeID = 0x2bf40ccc

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

func ( *AccountUpdateThemeRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Format == "") {
		return false
	}
	if !(.Theme == nil) {
		return false
	}
	if !(.Slug == "") {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Document == nil) {
		return false
	}
	if !(.Settings == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AccountUpdateThemeRequest from given interface.
func ( *AccountUpdateThemeRequest) ( interface {
	() ( string)
	() ( InputThemeClass)
	() ( string,  bool)
	() ( string,  bool)
	() ( InputDocumentClass,  bool)
	() ( []InputThemeSettings,  bool)
}) {
	.Format = .()
	.Theme = .()
	if ,  := .();  {
		.Slug = 
	}

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *AccountUpdateThemeRequest) () tdp.Type {
	 := tdp.Type{
		Name: "account.updateTheme",
		ID:   AccountUpdateThemeRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Format",
			SchemaName: "format",
		},
		{
			Name:       "Theme",
			SchemaName: "theme",
		},
		{
			Name:       "Slug",
			SchemaName: "slug",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Title",
			SchemaName: "title",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Document",
			SchemaName: "document",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AccountUpdateThemeRequest) () {
	if !(.Slug == "") {
		.Flags.Set(0)
	}
	if !(.Title == "") {
		.Flags.Set(1)
	}
	if !(.Document == nil) {
		.Flags.Set(2)
	}
	if !(.Settings == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *AccountUpdateThemeRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.updateTheme#2bf40ccc as nil")
	}
	.PutID(AccountUpdateThemeRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountUpdateThemeRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.updateTheme#2bf40ccc as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode account.updateTheme#2bf40ccc: field flags: %w", )
	}
	.PutString(.Format)
	if .Theme == nil {
		return fmt.Errorf("unable to encode account.updateTheme#2bf40ccc: field theme is nil")
	}
	if  := .Theme.Encode();  != nil {
		return fmt.Errorf("unable to encode account.updateTheme#2bf40ccc: field theme: %w", )
	}
	if .Flags.Has(0) {
		.PutString(.Slug)
	}
	if .Flags.Has(1) {
		.PutString(.Title)
	}
	if .Flags.Has(2) {
		if .Document == nil {
			return fmt.Errorf("unable to encode account.updateTheme#2bf40ccc: field document is nil")
		}
		if  := .Document.Encode();  != nil {
			return fmt.Errorf("unable to encode account.updateTheme#2bf40ccc: field document: %w", )
		}
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.Settings))
		for ,  := range .Settings {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode account.updateTheme#2bf40ccc: field settings element with index %d: %w", , )
			}
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *AccountUpdateThemeRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.updateTheme#2bf40ccc to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field format: %w", )
		}
		.Format = 
	}
	{
		,  := DecodeInputTheme()
		if  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field theme: %w", )
		}
		.Theme = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field slug: %w", )
		}
		.Slug = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(2) {
		,  := DecodeInputDocument()
		if  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field document: %w", )
		}
		.Document = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field settings: %w", )
		}

		if  > 0 {
			.Settings = make([]InputThemeSettings, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  InputThemeSettings
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode account.updateTheme#2bf40ccc: field settings: %w", )
			}
			.Settings = append(.Settings, )
		}
	}
	return nil
}

// GetFormat returns value of Format field.
func ( *AccountUpdateThemeRequest) () ( string) {
	if  == nil {
		return
	}
	return .Format
}

// GetTheme returns value of Theme field.
func ( *AccountUpdateThemeRequest) () ( InputThemeClass) {
	if  == nil {
		return
	}
	return .Theme
}

// SetSlug sets value of Slug conditional field.
func ( *AccountUpdateThemeRequest) ( string) {
	.Flags.Set(0)
	.Slug = 
}

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

// SetTitle sets value of Title conditional field.
func ( *AccountUpdateThemeRequest) ( string) {
	.Flags.Set(1)
	.Title = 
}

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

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

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

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

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

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

// AccountUpdateTheme invokes method account.updateTheme#2bf40ccc returning error if any.
// Update theme
//
// Possible errors:
//
//	400 THEME_INVALID: Invalid theme provided.
//
// See https://core.telegram.org/method/account.updateTheme for reference.
func ( *Client) ( context.Context,  *AccountUpdateThemeRequest) (*Theme, error) {
	var  Theme

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