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

// WebPageAttributeTheme represents TL type `webPageAttributeTheme#54b56617`.
// Page theme
//
// See https://core.telegram.org/constructor/webPageAttributeTheme for reference.
type WebPageAttributeTheme struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Theme files
	//
	// Use SetDocuments and GetDocuments helpers.
	Documents []DocumentClass
	// Theme settings
	//
	// Use SetSettings and GetSettings helpers.
	Settings ThemeSettings
}

// WebPageAttributeThemeTypeID is TL type id of WebPageAttributeTheme.
const WebPageAttributeThemeTypeID = 0x54b56617

// construct implements constructor of WebPageAttributeClass.
func ( WebPageAttributeTheme) () WebPageAttributeClass { return & }

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

	_ WebPageAttributeClass = &WebPageAttributeTheme{}
)

func ( *WebPageAttributeTheme) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Documents == nil) {
		return false
	}
	if !(.Settings.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills WebPageAttributeTheme from given interface.
func ( *WebPageAttributeTheme) ( interface {
	() ( []DocumentClass,  bool)
	() ( ThemeSettings,  bool)
}) {
	if ,  := .();  {
		.Documents = 
	}

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

}

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

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

// TypeInfo returns info about TL type.
func ( *WebPageAttributeTheme) () tdp.Type {
	 := tdp.Type{
		Name: "webPageAttributeTheme",
		ID:   WebPageAttributeThemeTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Documents",
			SchemaName: "documents",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WebPageAttributeTheme) () {
	if !(.Documents == nil) {
		.Flags.Set(0)
	}
	if !(.Settings.Zero()) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *WebPageAttributeTheme) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webPageAttributeTheme#54b56617 as nil")
	}
	.PutID(WebPageAttributeThemeTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WebPageAttributeTheme) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webPageAttributeTheme#54b56617 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode webPageAttributeTheme#54b56617: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutVectorHeader(len(.Documents))
		for ,  := range .Documents {
			if  == nil {
				return fmt.Errorf("unable to encode webPageAttributeTheme#54b56617: field documents element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode webPageAttributeTheme#54b56617: field documents element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(1) {
		if  := .Settings.Encode();  != nil {
			return fmt.Errorf("unable to encode webPageAttributeTheme#54b56617: field settings: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *WebPageAttributeTheme) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode webPageAttributeTheme#54b56617 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode webPageAttributeTheme#54b56617: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode webPageAttributeTheme#54b56617: field documents: %w", )
		}

		if  > 0 {
			.Documents = make([]DocumentClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeDocument()
			if  != nil {
				return fmt.Errorf("unable to decode webPageAttributeTheme#54b56617: field documents: %w", )
			}
			.Documents = append(.Documents, )
		}
	}
	if .Flags.Has(1) {
		if  := .Settings.Decode();  != nil {
			return fmt.Errorf("unable to decode webPageAttributeTheme#54b56617: field settings: %w", )
		}
	}
	return nil
}

// SetDocuments sets value of Documents conditional field.
func ( *WebPageAttributeTheme) ( []DocumentClass) {
	.Flags.Set(0)
	.Documents = 
}

// GetDocuments returns value of Documents conditional field and
// boolean which is true if field was set.
func ( *WebPageAttributeTheme) () ( []DocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Documents, true
}

// SetSettings sets value of Settings conditional field.
func ( *WebPageAttributeTheme) ( ThemeSettings) {
	.Flags.Set(1)
	.Settings = 
}

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

// MapDocuments returns field Documents wrapped in DocumentClassArray helper.
func ( *WebPageAttributeTheme) () ( DocumentClassArray,  bool) {
	if !.Flags.Has(0) {
		return , false
	}
	return DocumentClassArray(.Documents), true
}

// WebPageAttributeStory represents TL type `webPageAttributeStory#2e94c3e7`.
// Webpage preview of a Telegram story
//
// See https://core.telegram.org/constructor/webPageAttributeStory for reference.
type WebPageAttributeStory struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Peer that posted the story
	Peer PeerClass
	// Story ID¹
	//
	// Links:
	//  1) https://core.telegram.org/api/stories#watching-stories
	ID int
	// May contain the story, if not the story should be fetched when and if needed using
	// stories.getStoriesByID¹ with the above id and peer.
	//
	// Links:
	//  1) https://core.telegram.org/method/stories.getStoriesByID
	//
	// Use SetStory and GetStory helpers.
	Story StoryItemClass
}

// WebPageAttributeStoryTypeID is TL type id of WebPageAttributeStory.
const WebPageAttributeStoryTypeID = 0x2e94c3e7

// construct implements constructor of WebPageAttributeClass.
func ( WebPageAttributeStory) () WebPageAttributeClass { return & }

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

	_ WebPageAttributeClass = &WebPageAttributeStory{}
)

func ( *WebPageAttributeStory) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Story == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WebPageAttributeStory from given interface.
func ( *WebPageAttributeStory) ( interface {
	() ( PeerClass)
	() ( int)
	() ( StoryItemClass,  bool)
}) {
	.Peer = .()
	.ID = .()
	if ,  := .();  {
		.Story = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *WebPageAttributeStory) () tdp.Type {
	 := tdp.Type{
		Name: "webPageAttributeStory",
		ID:   WebPageAttributeStoryTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Story",
			SchemaName: "story",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WebPageAttributeStory) () {
	if !(.Story == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *WebPageAttributeStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webPageAttributeStory#2e94c3e7 as nil")
	}
	.PutID(WebPageAttributeStoryTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WebPageAttributeStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webPageAttributeStory#2e94c3e7 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode webPageAttributeStory#2e94c3e7: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode webPageAttributeStory#2e94c3e7: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode webPageAttributeStory#2e94c3e7: field peer: %w", )
	}
	.PutInt(.ID)
	if .Flags.Has(0) {
		if .Story == nil {
			return fmt.Errorf("unable to encode webPageAttributeStory#2e94c3e7: field story is nil")
		}
		if  := .Story.Encode();  != nil {
			return fmt.Errorf("unable to encode webPageAttributeStory#2e94c3e7: field story: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *WebPageAttributeStory) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode webPageAttributeStory#2e94c3e7 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode webPageAttributeStory#2e94c3e7: field flags: %w", )
		}
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode webPageAttributeStory#2e94c3e7: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode webPageAttributeStory#2e94c3e7: field id: %w", )
		}
		.ID = 
	}
	if .Flags.Has(0) {
		,  := DecodeStoryItem()
		if  != nil {
			return fmt.Errorf("unable to decode webPageAttributeStory#2e94c3e7: field story: %w", )
		}
		.Story = 
	}
	return nil
}

// GetPeer returns value of Peer field.
func ( *WebPageAttributeStory) () ( PeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

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

// SetStory sets value of Story conditional field.
func ( *WebPageAttributeStory) ( StoryItemClass) {
	.Flags.Set(0)
	.Story = 
}

// GetStory returns value of Story conditional field and
// boolean which is true if field was set.
func ( *WebPageAttributeStory) () ( StoryItemClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Story, true
}

// WebPageAttributeClassName is schema name of WebPageAttributeClass.
const WebPageAttributeClassName = "WebPageAttribute"

// WebPageAttributeClass represents WebPageAttribute generic type.
//
// See https://core.telegram.org/type/WebPageAttribute for reference.
//
// Example:
//
//	g, err := tg.DecodeWebPageAttribute(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.WebPageAttributeTheme: // webPageAttributeTheme#54b56617
//	case *tg.WebPageAttributeStory: // webPageAttributeStory#2e94c3e7
//	default: panic(v)
//	}
type WebPageAttributeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() WebPageAttributeClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool
}

// DecodeWebPageAttribute implements binary de-serialization for WebPageAttributeClass.
func ( *bin.Buffer) (WebPageAttributeClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case WebPageAttributeThemeTypeID:
		// Decoding webPageAttributeTheme#54b56617.
		 := WebPageAttributeTheme{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", )
		}
		return &, nil
	case WebPageAttributeStoryTypeID:
		// Decoding webPageAttributeStory#2e94c3e7.
		 := WebPageAttributeStory{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", bin.NewUnexpectedID())
	}
}

// WebPageAttribute boxes the WebPageAttributeClass providing a helper.
type WebPageAttributeBox struct {
	WebPageAttribute WebPageAttributeClass
}

// Decode implements bin.Decoder for WebPageAttributeBox.
func ( *WebPageAttributeBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode WebPageAttributeBox to nil")
	}
	,  := DecodeWebPageAttribute()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.WebPageAttribute = 
	return nil
}

// Encode implements bin.Encode for WebPageAttributeBox.
func ( *WebPageAttributeBox) ( *bin.Buffer) error {
	if  == nil || .WebPageAttribute == nil {
		return fmt.Errorf("unable to encode WebPageAttributeClass as nil")
	}
	return .WebPageAttribute.Encode()
}