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

// PageListItemText represents TL type `pageListItemText#b92fb6cd`.
// List item
//
// See https://core.telegram.org/constructor/pageListItemText for reference.
type PageListItemText struct {
	// Text
	Text RichTextClass
}

// PageListItemTextTypeID is TL type id of PageListItemText.
const PageListItemTextTypeID = 0xb92fb6cd

// construct implements constructor of PageListItemClass.
func ( PageListItemText) () PageListItemClass { return & }

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

	_ PageListItemClass = &PageListItemText{}
)

func ( *PageListItemText) () bool {
	if  == nil {
		return true
	}
	if !(.Text == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PageListItemText from given interface.
func ( *PageListItemText) ( interface {
	() ( RichTextClass)
}) {
	.Text = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PageListItemText) () tdp.Type {
	 := tdp.Type{
		Name: "pageListItemText",
		ID:   PageListItemTextTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Text",
			SchemaName: "text",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PageListItemText) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pageListItemText#b92fb6cd as nil")
	}
	.PutID(PageListItemTextTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PageListItemText) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pageListItemText#b92fb6cd as nil")
	}
	if .Text == nil {
		return fmt.Errorf("unable to encode pageListItemText#b92fb6cd: field text is nil")
	}
	if  := .Text.Encode();  != nil {
		return fmt.Errorf("unable to encode pageListItemText#b92fb6cd: field text: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PageListItemText) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pageListItemText#b92fb6cd to nil")
	}
	{
		,  := DecodeRichText()
		if  != nil {
			return fmt.Errorf("unable to decode pageListItemText#b92fb6cd: field text: %w", )
		}
		.Text = 
	}
	return nil
}

// GetText returns value of Text field.
func ( *PageListItemText) () ( RichTextClass) {
	if  == nil {
		return
	}
	return .Text
}

// PageListItemBlocks represents TL type `pageListItemBlocks#25e073fc`.
// List item
//
// See https://core.telegram.org/constructor/pageListItemBlocks for reference.
type PageListItemBlocks struct {
	// Blocks
	Blocks []PageBlockClass
}

// PageListItemBlocksTypeID is TL type id of PageListItemBlocks.
const PageListItemBlocksTypeID = 0x25e073fc

// construct implements constructor of PageListItemClass.
func ( PageListItemBlocks) () PageListItemClass { return & }

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

	_ PageListItemClass = &PageListItemBlocks{}
)

func ( *PageListItemBlocks) () bool {
	if  == nil {
		return true
	}
	if !(.Blocks == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PageListItemBlocks from given interface.
func ( *PageListItemBlocks) ( interface {
	() ( []PageBlockClass)
}) {
	.Blocks = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PageListItemBlocks) () tdp.Type {
	 := tdp.Type{
		Name: "pageListItemBlocks",
		ID:   PageListItemBlocksTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Blocks",
			SchemaName: "blocks",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PageListItemBlocks) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pageListItemBlocks#25e073fc as nil")
	}
	.PutID(PageListItemBlocksTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PageListItemBlocks) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pageListItemBlocks#25e073fc as nil")
	}
	.PutVectorHeader(len(.Blocks))
	for ,  := range .Blocks {
		if  == nil {
			return fmt.Errorf("unable to encode pageListItemBlocks#25e073fc: field blocks element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode pageListItemBlocks#25e073fc: field blocks element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PageListItemBlocks) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pageListItemBlocks#25e073fc to nil")
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode pageListItemBlocks#25e073fc: field blocks: %w", )
		}

		if  > 0 {
			.Blocks = make([]PageBlockClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePageBlock()
			if  != nil {
				return fmt.Errorf("unable to decode pageListItemBlocks#25e073fc: field blocks: %w", )
			}
			.Blocks = append(.Blocks, )
		}
	}
	return nil
}

// GetBlocks returns value of Blocks field.
func ( *PageListItemBlocks) () ( []PageBlockClass) {
	if  == nil {
		return
	}
	return .Blocks
}

// MapBlocks returns field Blocks wrapped in PageBlockClassArray helper.
func ( *PageListItemBlocks) () ( PageBlockClassArray) {
	return PageBlockClassArray(.Blocks)
}

// PageListItemClassName is schema name of PageListItemClass.
const PageListItemClassName = "PageListItem"

// PageListItemClass represents PageListItem generic type.
//
// See https://core.telegram.org/type/PageListItem for reference.
//
// Example:
//
//	g, err := tg.DecodePageListItem(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PageListItemText: // pageListItemText#b92fb6cd
//	case *tg.PageListItemBlocks: // pageListItemBlocks#25e073fc
//	default: panic(v)
//	}
type PageListItemClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PageListItemClass

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

// DecodePageListItem implements binary de-serialization for PageListItemClass.
func ( *bin.Buffer) (PageListItemClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case PageListItemTextTypeID:
		// Decoding pageListItemText#b92fb6cd.
		 := PageListItemText{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PageListItemClass: %w", )
		}
		return &, nil
	case PageListItemBlocksTypeID:
		// Decoding pageListItemBlocks#25e073fc.
		 := PageListItemBlocks{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PageListItemClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode PageListItemClass: %w", bin.NewUnexpectedID())
	}
}

// PageListItem boxes the PageListItemClass providing a helper.
type PageListItemBox struct {
	PageListItem PageListItemClass
}

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

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