// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// 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 (w WebPageAttributeTheme) construct() WebPageAttributeClass { return &w }

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

	_ WebPageAttributeClass = &WebPageAttributeTheme{}
)

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

	return true
}

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

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

	if val, ok := from.GetSettings(); ok {
		w.Settings = val
	}

}

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

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

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

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

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

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

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

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

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

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

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

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

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

// MapDocuments returns field Documents wrapped in DocumentClassArray helper.
func (w *WebPageAttributeTheme) MapDocuments() (value DocumentClassArray, ok bool) {
	if !w.Flags.Has(0) {
		return value, false
	}
	return DocumentClassArray(w.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 (w WebPageAttributeStory) construct() WebPageAttributeClass { return &w }

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

	_ WebPageAttributeClass = &WebPageAttributeStory{}
)

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

	return true
}

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

// FillFrom fills WebPageAttributeStory from given interface.
func (w *WebPageAttributeStory) FillFrom(from interface {
	GetPeer() (value PeerClass)
	GetID() (value int)
	GetStory() (value StoryItemClass, ok bool)
}) {
	w.Peer = from.GetPeer()
	w.ID = from.GetID()
	if val, ok := from.GetStory(); ok {
		w.Story = val
	}

}

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

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

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

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

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

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

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

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

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

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

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

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

// WebPageAttributeStickerSet represents TL type `webPageAttributeStickerSet#50cc03d3`.
// Contains info about a stickerset »¹, for a webPage² preview of a stickerset deep
// link »³ (the webPage⁴ will have a type of telegram_stickerset).
//
// Links:
//  1. https://core.telegram.org/api/stickers
//  2. https://core.telegram.org/constructor/webPage
//  3. https://core.telegram.org/api/links#stickerset-links
//  4. https://core.telegram.org/constructor/webPage
//
// See https://core.telegram.org/constructor/webPageAttributeStickerSet for reference.
type WebPageAttributeStickerSet struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this i s a custom emoji stickerset¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/custom-emoji
	Emojis bool
	// Whether the color of this TGS custom emoji stickerset should be changed to the text
	// color when used in messages, the accent color if used as emoji status, white on chat
	// photos, or another appropriate color based on context.
	TextColor bool
	// A subset of the stickerset in the stickerset.
	Stickers []DocumentClass
}

// WebPageAttributeStickerSetTypeID is TL type id of WebPageAttributeStickerSet.
const WebPageAttributeStickerSetTypeID = 0x50cc03d3

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

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

	_ WebPageAttributeClass = &WebPageAttributeStickerSet{}
)

func (w *WebPageAttributeStickerSet) Zero() bool {
	if w == nil {
		return true
	}
	if !(w.Flags.Zero()) {
		return false
	}
	if !(w.Emojis == false) {
		return false
	}
	if !(w.TextColor == false) {
		return false
	}
	if !(w.Stickers == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WebPageAttributeStickerSet from given interface.
func (w *WebPageAttributeStickerSet) FillFrom(from interface {
	GetEmojis() (value bool)
	GetTextColor() (value bool)
	GetStickers() (value []DocumentClass)
}) {
	w.Emojis = from.GetEmojis()
	w.TextColor = from.GetTextColor()
	w.Stickers = from.GetStickers()
}

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

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

// TypeInfo returns info about TL type.
func (w *WebPageAttributeStickerSet) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "webPageAttributeStickerSet",
		ID:   WebPageAttributeStickerSetTypeID,
	}
	if w == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Emojis",
			SchemaName: "emojis",
			Null:       !w.Flags.Has(0),
		},
		{
			Name:       "TextColor",
			SchemaName: "text_color",
			Null:       !w.Flags.Has(1),
		},
		{
			Name:       "Stickers",
			SchemaName: "stickers",
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (w *WebPageAttributeStickerSet) SetFlags() {
	if !(w.Emojis == false) {
		w.Flags.Set(0)
	}
	if !(w.TextColor == false) {
		w.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func (w *WebPageAttributeStickerSet) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeStickerSet#50cc03d3 as nil")
	}
	b.PutID(WebPageAttributeStickerSetTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebPageAttributeStickerSet) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeStickerSet#50cc03d3 as nil")
	}
	w.SetFlags()
	if err := w.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode webPageAttributeStickerSet#50cc03d3: field flags: %w", err)
	}
	b.PutVectorHeader(len(w.Stickers))
	for idx, v := range w.Stickers {
		if v == nil {
			return fmt.Errorf("unable to encode webPageAttributeStickerSet#50cc03d3: field stickers element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode webPageAttributeStickerSet#50cc03d3: field stickers element with index %d: %w", idx, err)
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func (w *WebPageAttributeStickerSet) Decode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeStickerSet#50cc03d3 to nil")
	}
	if err := b.ConsumeID(WebPageAttributeStickerSetTypeID); err != nil {
		return fmt.Errorf("unable to decode webPageAttributeStickerSet#50cc03d3: %w", err)
	}
	return w.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (w *WebPageAttributeStickerSet) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeStickerSet#50cc03d3 to nil")
	}
	{
		if err := w.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode webPageAttributeStickerSet#50cc03d3: field flags: %w", err)
		}
	}
	w.Emojis = w.Flags.Has(0)
	w.TextColor = w.Flags.Has(1)
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode webPageAttributeStickerSet#50cc03d3: field stickers: %w", err)
		}

		if headerLen > 0 {
			w.Stickers = make([]DocumentClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeDocument(b)
			if err != nil {
				return fmt.Errorf("unable to decode webPageAttributeStickerSet#50cc03d3: field stickers: %w", err)
			}
			w.Stickers = append(w.Stickers, value)
		}
	}
	return nil
}

// SetEmojis sets value of Emojis conditional field.
func (w *WebPageAttributeStickerSet) SetEmojis(value bool) {
	if value {
		w.Flags.Set(0)
		w.Emojis = true
	} else {
		w.Flags.Unset(0)
		w.Emojis = false
	}
}

// GetEmojis returns value of Emojis conditional field.
func (w *WebPageAttributeStickerSet) GetEmojis() (value bool) {
	if w == nil {
		return
	}
	return w.Flags.Has(0)
}

// SetTextColor sets value of TextColor conditional field.
func (w *WebPageAttributeStickerSet) SetTextColor(value bool) {
	if value {
		w.Flags.Set(1)
		w.TextColor = true
	} else {
		w.Flags.Unset(1)
		w.TextColor = false
	}
}

// GetTextColor returns value of TextColor conditional field.
func (w *WebPageAttributeStickerSet) GetTextColor() (value bool) {
	if w == nil {
		return
	}
	return w.Flags.Has(1)
}

// GetStickers returns value of Stickers field.
func (w *WebPageAttributeStickerSet) GetStickers() (value []DocumentClass) {
	if w == nil {
		return
	}
	return w.Stickers
}

// MapStickers returns field Stickers wrapped in DocumentClassArray helper.
func (w *WebPageAttributeStickerSet) MapStickers() (value DocumentClassArray) {
	return DocumentClassArray(w.Stickers)
}

// WebPageAttributeUniqueStarGift represents TL type `webPageAttributeUniqueStarGift#cf6f6db8`.
// Contains info about collectible gift »¹ for a webPage² preview of a collectible
// gift »³ (the webPage⁴ will have a type of telegram_nft).
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://core.telegram.org/constructor/webPage
//  3. https://core.telegram.org/api/gifts#collectible-gifts
//  4. https://core.telegram.org/constructor/webPage
//
// See https://core.telegram.org/constructor/webPageAttributeUniqueStarGift for reference.
type WebPageAttributeUniqueStarGift struct {
	// The starGiftUnique¹ constructor.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftUnique
	Gift StarGiftClass
}

// WebPageAttributeUniqueStarGiftTypeID is TL type id of WebPageAttributeUniqueStarGift.
const WebPageAttributeUniqueStarGiftTypeID = 0xcf6f6db8

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

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

	_ WebPageAttributeClass = &WebPageAttributeUniqueStarGift{}
)

func (w *WebPageAttributeUniqueStarGift) Zero() bool {
	if w == nil {
		return true
	}
	if !(w.Gift == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WebPageAttributeUniqueStarGift from given interface.
func (w *WebPageAttributeUniqueStarGift) FillFrom(from interface {
	GetGift() (value StarGiftClass)
}) {
	w.Gift = from.GetGift()
}

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

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

// TypeInfo returns info about TL type.
func (w *WebPageAttributeUniqueStarGift) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "webPageAttributeUniqueStarGift",
		ID:   WebPageAttributeUniqueStarGiftTypeID,
	}
	if w == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Gift",
			SchemaName: "gift",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (w *WebPageAttributeUniqueStarGift) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeUniqueStarGift#cf6f6db8 as nil")
	}
	b.PutID(WebPageAttributeUniqueStarGiftTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebPageAttributeUniqueStarGift) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeUniqueStarGift#cf6f6db8 as nil")
	}
	if w.Gift == nil {
		return fmt.Errorf("unable to encode webPageAttributeUniqueStarGift#cf6f6db8: field gift is nil")
	}
	if err := w.Gift.Encode(b); err != nil {
		return fmt.Errorf("unable to encode webPageAttributeUniqueStarGift#cf6f6db8: field gift: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (w *WebPageAttributeUniqueStarGift) Decode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeUniqueStarGift#cf6f6db8 to nil")
	}
	if err := b.ConsumeID(WebPageAttributeUniqueStarGiftTypeID); err != nil {
		return fmt.Errorf("unable to decode webPageAttributeUniqueStarGift#cf6f6db8: %w", err)
	}
	return w.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (w *WebPageAttributeUniqueStarGift) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeUniqueStarGift#cf6f6db8 to nil")
	}
	{
		value, err := DecodeStarGift(b)
		if err != nil {
			return fmt.Errorf("unable to decode webPageAttributeUniqueStarGift#cf6f6db8: field gift: %w", err)
		}
		w.Gift = value
	}
	return nil
}

// GetGift returns value of Gift field.
func (w *WebPageAttributeUniqueStarGift) GetGift() (value StarGiftClass) {
	if w == nil {
		return
	}
	return w.Gift
}

// WebPageAttributeStarGiftCollection represents TL type `webPageAttributeStarGiftCollection#31cad303`.
// Contains info about a gift collection »¹ for a webPage² preview of a gift
// collection »³ (the webPage⁴ will have a type of telegram_collection).
//
// Links:
//  1. https://core.telegram.org/api/gifts#gift-collections
//  2. https://core.telegram.org/constructor/webPage
//  3. https://core.telegram.org/api/gifts#gift-collections
//  4. https://core.telegram.org/constructor/webPage
//
// See https://core.telegram.org/constructor/webPageAttributeStarGiftCollection for reference.
type WebPageAttributeStarGiftCollection struct {
	// Gifts in the collection.
	Icons []DocumentClass
}

// WebPageAttributeStarGiftCollectionTypeID is TL type id of WebPageAttributeStarGiftCollection.
const WebPageAttributeStarGiftCollectionTypeID = 0x31cad303

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

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

	_ WebPageAttributeClass = &WebPageAttributeStarGiftCollection{}
)

func (w *WebPageAttributeStarGiftCollection) Zero() bool {
	if w == nil {
		return true
	}
	if !(w.Icons == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WebPageAttributeStarGiftCollection from given interface.
func (w *WebPageAttributeStarGiftCollection) FillFrom(from interface {
	GetIcons() (value []DocumentClass)
}) {
	w.Icons = from.GetIcons()
}

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

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

// TypeInfo returns info about TL type.
func (w *WebPageAttributeStarGiftCollection) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "webPageAttributeStarGiftCollection",
		ID:   WebPageAttributeStarGiftCollectionTypeID,
	}
	if w == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Icons",
			SchemaName: "icons",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (w *WebPageAttributeStarGiftCollection) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeStarGiftCollection#31cad303 as nil")
	}
	b.PutID(WebPageAttributeStarGiftCollectionTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebPageAttributeStarGiftCollection) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeStarGiftCollection#31cad303 as nil")
	}
	b.PutVectorHeader(len(w.Icons))
	for idx, v := range w.Icons {
		if v == nil {
			return fmt.Errorf("unable to encode webPageAttributeStarGiftCollection#31cad303: field icons element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode webPageAttributeStarGiftCollection#31cad303: field icons element with index %d: %w", idx, err)
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func (w *WebPageAttributeStarGiftCollection) Decode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeStarGiftCollection#31cad303 to nil")
	}
	if err := b.ConsumeID(WebPageAttributeStarGiftCollectionTypeID); err != nil {
		return fmt.Errorf("unable to decode webPageAttributeStarGiftCollection#31cad303: %w", err)
	}
	return w.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (w *WebPageAttributeStarGiftCollection) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeStarGiftCollection#31cad303 to nil")
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode webPageAttributeStarGiftCollection#31cad303: field icons: %w", err)
		}

		if headerLen > 0 {
			w.Icons = make([]DocumentClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeDocument(b)
			if err != nil {
				return fmt.Errorf("unable to decode webPageAttributeStarGiftCollection#31cad303: field icons: %w", err)
			}
			w.Icons = append(w.Icons, value)
		}
	}
	return nil
}

// GetIcons returns value of Icons field.
func (w *WebPageAttributeStarGiftCollection) GetIcons() (value []DocumentClass) {
	if w == nil {
		return
	}
	return w.Icons
}

// MapIcons returns field Icons wrapped in DocumentClassArray helper.
func (w *WebPageAttributeStarGiftCollection) MapIcons() (value DocumentClassArray) {
	return DocumentClassArray(w.Icons)
}

// WebPageAttributeStarGiftAuction represents TL type `webPageAttributeStarGiftAuction#1c641c2`.
//
// See https://core.telegram.org/constructor/webPageAttributeStarGiftAuction for reference.
type WebPageAttributeStarGiftAuction struct {
	// Gift field of WebPageAttributeStarGiftAuction.
	Gift StarGiftClass
	// EndDate field of WebPageAttributeStarGiftAuction.
	EndDate int
}

// WebPageAttributeStarGiftAuctionTypeID is TL type id of WebPageAttributeStarGiftAuction.
const WebPageAttributeStarGiftAuctionTypeID = 0x1c641c2

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

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

	_ WebPageAttributeClass = &WebPageAttributeStarGiftAuction{}
)

func (w *WebPageAttributeStarGiftAuction) Zero() bool {
	if w == nil {
		return true
	}
	if !(w.Gift == nil) {
		return false
	}
	if !(w.EndDate == 0) {
		return false
	}

	return true
}

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

// FillFrom fills WebPageAttributeStarGiftAuction from given interface.
func (w *WebPageAttributeStarGiftAuction) FillFrom(from interface {
	GetGift() (value StarGiftClass)
	GetEndDate() (value int)
}) {
	w.Gift = from.GetGift()
	w.EndDate = from.GetEndDate()
}

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

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

// TypeInfo returns info about TL type.
func (w *WebPageAttributeStarGiftAuction) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "webPageAttributeStarGiftAuction",
		ID:   WebPageAttributeStarGiftAuctionTypeID,
	}
	if w == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Gift",
			SchemaName: "gift",
		},
		{
			Name:       "EndDate",
			SchemaName: "end_date",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (w *WebPageAttributeStarGiftAuction) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeStarGiftAuction#1c641c2 as nil")
	}
	b.PutID(WebPageAttributeStarGiftAuctionTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebPageAttributeStarGiftAuction) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webPageAttributeStarGiftAuction#1c641c2 as nil")
	}
	if w.Gift == nil {
		return fmt.Errorf("unable to encode webPageAttributeStarGiftAuction#1c641c2: field gift is nil")
	}
	if err := w.Gift.Encode(b); err != nil {
		return fmt.Errorf("unable to encode webPageAttributeStarGiftAuction#1c641c2: field gift: %w", err)
	}
	b.PutInt(w.EndDate)
	return nil
}

// Decode implements bin.Decoder.
func (w *WebPageAttributeStarGiftAuction) Decode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeStarGiftAuction#1c641c2 to nil")
	}
	if err := b.ConsumeID(WebPageAttributeStarGiftAuctionTypeID); err != nil {
		return fmt.Errorf("unable to decode webPageAttributeStarGiftAuction#1c641c2: %w", err)
	}
	return w.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (w *WebPageAttributeStarGiftAuction) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webPageAttributeStarGiftAuction#1c641c2 to nil")
	}
	{
		value, err := DecodeStarGift(b)
		if err != nil {
			return fmt.Errorf("unable to decode webPageAttributeStarGiftAuction#1c641c2: field gift: %w", err)
		}
		w.Gift = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode webPageAttributeStarGiftAuction#1c641c2: field end_date: %w", err)
		}
		w.EndDate = value
	}
	return nil
}

// GetGift returns value of Gift field.
func (w *WebPageAttributeStarGiftAuction) GetGift() (value StarGiftClass) {
	if w == nil {
		return
	}
	return w.Gift
}

// GetEndDate returns value of EndDate field.
func (w *WebPageAttributeStarGiftAuction) GetEndDate() (value int) {
	if w == nil {
		return
	}
	return w.EndDate
}

// 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
//	case *tg.WebPageAttributeStickerSet: // webPageAttributeStickerSet#50cc03d3
//	case *tg.WebPageAttributeUniqueStarGift: // webPageAttributeUniqueStarGift#cf6f6db8
//	case *tg.WebPageAttributeStarGiftCollection: // webPageAttributeStarGiftCollection#31cad303
//	case *tg.WebPageAttributeStarGiftAuction: // webPageAttributeStarGiftAuction#1c641c2
//	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 DecodeWebPageAttribute(buf *bin.Buffer) (WebPageAttributeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case WebPageAttributeThemeTypeID:
		// Decoding webPageAttributeTheme#54b56617.
		v := WebPageAttributeTheme{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", err)
		}
		return &v, nil
	case WebPageAttributeStoryTypeID:
		// Decoding webPageAttributeStory#2e94c3e7.
		v := WebPageAttributeStory{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", err)
		}
		return &v, nil
	case WebPageAttributeStickerSetTypeID:
		// Decoding webPageAttributeStickerSet#50cc03d3.
		v := WebPageAttributeStickerSet{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", err)
		}
		return &v, nil
	case WebPageAttributeUniqueStarGiftTypeID:
		// Decoding webPageAttributeUniqueStarGift#cf6f6db8.
		v := WebPageAttributeUniqueStarGift{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", err)
		}
		return &v, nil
	case WebPageAttributeStarGiftCollectionTypeID:
		// Decoding webPageAttributeStarGiftCollection#31cad303.
		v := WebPageAttributeStarGiftCollection{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", err)
		}
		return &v, nil
	case WebPageAttributeStarGiftAuctionTypeID:
		// Decoding webPageAttributeStarGiftAuction#1c641c2.
		v := WebPageAttributeStarGiftAuction{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode WebPageAttributeClass: %w", bin.NewUnexpectedID(id))
	}
}

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

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

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