// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// LinkPreviewTypeAlbum represents TL type `linkPreviewTypeAlbum#186d97b4`.
type LinkPreviewTypeAlbum struct {
	// The list of album media
	Media []LinkPreviewAlbumMediaClass
	// Album caption
	Caption string
}

// LinkPreviewTypeAlbumTypeID is TL type id of LinkPreviewTypeAlbum.
const LinkPreviewTypeAlbumTypeID = 0x186d97b4

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeAlbum) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeAlbum{}
)

func (l *LinkPreviewTypeAlbum) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Media == nil) {
		return false
	}
	if !(l.Caption == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeAlbum) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeAlbum",
		ID:   LinkPreviewTypeAlbumTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Media",
			SchemaName: "media",
		},
		{
			Name:       "Caption",
			SchemaName: "caption",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeAlbum) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAlbum#186d97b4 as nil")
	}
	b.PutID(LinkPreviewTypeAlbumTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeAlbum) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAlbum#186d97b4 as nil")
	}
	b.PutInt(len(l.Media))
	for idx, v := range l.Media {
		if v == nil {
			return fmt.Errorf("unable to encode linkPreviewTypeAlbum#186d97b4: field media element with index %d is nil", idx)
		}
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare linkPreviewTypeAlbum#186d97b4: field media element with index %d: %w", idx, err)
		}
	}
	b.PutString(l.Caption)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeAlbum) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAlbum#186d97b4 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeAlbumTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeAlbum) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAlbum#186d97b4 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: field media: %w", err)
		}

		if headerLen > 0 {
			l.Media = make([]LinkPreviewAlbumMediaClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeLinkPreviewAlbumMedia(b)
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: field media: %w", err)
			}
			l.Media = append(l.Media, value)
		}
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: field caption: %w", err)
		}
		l.Caption = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeAlbum) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAlbum#186d97b4 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeAlbum")
	b.Comma()
	b.FieldStart("media")
	b.ArrStart()
	for idx, v := range l.Media {
		if v == nil {
			return fmt.Errorf("unable to encode linkPreviewTypeAlbum#186d97b4: field media element with index %d is nil", idx)
		}
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode linkPreviewTypeAlbum#186d97b4: field media element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.FieldStart("caption")
	b.PutString(l.Caption)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeAlbum) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAlbum#186d97b4 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeAlbum"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: %w", err)
			}
		case "media":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := DecodeTDLibJSONLinkPreviewAlbumMedia(b)
				if err != nil {
					return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: field media: %w", err)
				}
				l.Media = append(l.Media, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: field media: %w", err)
			}
		case "caption":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAlbum#186d97b4: field caption: %w", err)
			}
			l.Caption = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetMedia returns value of Media field.
func (l *LinkPreviewTypeAlbum) GetMedia() (value []LinkPreviewAlbumMediaClass) {
	if l == nil {
		return
	}
	return l.Media
}

// GetCaption returns value of Caption field.
func (l *LinkPreviewTypeAlbum) GetCaption() (value string) {
	if l == nil {
		return
	}
	return l.Caption
}

// LinkPreviewTypeAnimation represents TL type `linkPreviewTypeAnimation#ad5cc534`.
type LinkPreviewTypeAnimation struct {
	// The animation
	Animation Animation
}

// LinkPreviewTypeAnimationTypeID is TL type id of LinkPreviewTypeAnimation.
const LinkPreviewTypeAnimationTypeID = 0xad5cc534

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeAnimation) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeAnimation{}
)

func (l *LinkPreviewTypeAnimation) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Animation.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeAnimation) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeAnimation",
		ID:   LinkPreviewTypeAnimationTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Animation",
			SchemaName: "animation",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeAnimation) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAnimation#ad5cc534 as nil")
	}
	b.PutID(LinkPreviewTypeAnimationTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeAnimation) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAnimation#ad5cc534 as nil")
	}
	if err := l.Animation.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeAnimation#ad5cc534: field animation: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeAnimation) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAnimation#ad5cc534 to nil")
	}
	{
		if err := l.Animation.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeAnimation#ad5cc534: field animation: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeAnimation) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAnimation#ad5cc534 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeAnimation")
	b.Comma()
	b.FieldStart("animation")
	if err := l.Animation.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeAnimation#ad5cc534: field animation: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeAnimation) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAnimation#ad5cc534 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeAnimation"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAnimation#ad5cc534: %w", err)
			}
		case "animation":
			if err := l.Animation.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAnimation#ad5cc534: field animation: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetAnimation returns value of Animation field.
func (l *LinkPreviewTypeAnimation) GetAnimation() (value Animation) {
	if l == nil {
		return
	}
	return l.Animation
}

// LinkPreviewTypeApp represents TL type `linkPreviewTypeApp#e3a68def`.
type LinkPreviewTypeApp struct {
	// Photo for the app
	Photo Photo
}

// LinkPreviewTypeAppTypeID is TL type id of LinkPreviewTypeApp.
const LinkPreviewTypeAppTypeID = 0xe3a68def

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeApp) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeApp{}
)

func (l *LinkPreviewTypeApp) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeApp) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeApp",
		ID:   LinkPreviewTypeAppTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeApp) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeApp#e3a68def as nil")
	}
	b.PutID(LinkPreviewTypeAppTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeApp) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeApp#e3a68def as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeApp#e3a68def: field photo: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeApp) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeApp#e3a68def to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeApp#e3a68def: field photo: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeApp) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeApp#e3a68def as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeApp")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeApp#e3a68def: field photo: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeApp) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeApp#e3a68def to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeApp"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeApp#e3a68def: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeApp#e3a68def: field photo: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeApp) GetPhoto() (value Photo) {
	if l == nil {
		return
	}
	return l.Photo
}

// LinkPreviewTypeArticle represents TL type `linkPreviewTypeArticle#7cce9bd9`.
type LinkPreviewTypeArticle struct {
	// Article's main photo; may be null
	Photo Photo
}

// LinkPreviewTypeArticleTypeID is TL type id of LinkPreviewTypeArticle.
const LinkPreviewTypeArticleTypeID = 0x7cce9bd9

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeArticle) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeArticle{}
)

func (l *LinkPreviewTypeArticle) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeArticle) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeArticle",
		ID:   LinkPreviewTypeArticleTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeArticle) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeArticle#7cce9bd9 as nil")
	}
	b.PutID(LinkPreviewTypeArticleTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeArticle) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeArticle#7cce9bd9 as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeArticle#7cce9bd9: field photo: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeArticle) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeArticle#7cce9bd9 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeArticleTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeArticle#7cce9bd9: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeArticle) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeArticle#7cce9bd9 to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeArticle#7cce9bd9: field photo: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeArticle) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeArticle#7cce9bd9 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeArticle")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeArticle#7cce9bd9: field photo: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeArticle) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeArticle#7cce9bd9 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeArticle"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeArticle#7cce9bd9: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeArticle#7cce9bd9: field photo: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeArticle) GetPhoto() (value Photo) {
	if l == nil {
		return
	}
	return l.Photo
}

// LinkPreviewTypeAudio represents TL type `linkPreviewTypeAudio#75e407d2`.
type LinkPreviewTypeAudio struct {
	// The audio description
	Audio Audio
}

// LinkPreviewTypeAudioTypeID is TL type id of LinkPreviewTypeAudio.
const LinkPreviewTypeAudioTypeID = 0x75e407d2

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeAudio) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeAudio{}
)

func (l *LinkPreviewTypeAudio) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Audio.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeAudio) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeAudio",
		ID:   LinkPreviewTypeAudioTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Audio",
			SchemaName: "audio",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeAudio) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAudio#75e407d2 as nil")
	}
	b.PutID(LinkPreviewTypeAudioTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeAudio) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAudio#75e407d2 as nil")
	}
	if err := l.Audio.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeAudio#75e407d2: field audio: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeAudio) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAudio#75e407d2 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeAudioTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeAudio#75e407d2: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeAudio) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAudio#75e407d2 to nil")
	}
	{
		if err := l.Audio.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeAudio#75e407d2: field audio: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeAudio) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeAudio#75e407d2 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeAudio")
	b.Comma()
	b.FieldStart("audio")
	if err := l.Audio.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeAudio#75e407d2: field audio: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeAudio) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeAudio#75e407d2 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeAudio"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAudio#75e407d2: %w", err)
			}
		case "audio":
			if err := l.Audio.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeAudio#75e407d2: field audio: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetAudio returns value of Audio field.
func (l *LinkPreviewTypeAudio) GetAudio() (value Audio) {
	if l == nil {
		return
	}
	return l.Audio
}

// LinkPreviewTypeBackground represents TL type `linkPreviewTypeBackground#3a48a1e0`.
type LinkPreviewTypeBackground struct {
	// Document with the background; may be null for filled backgrounds
	Document Document
	// Type of the background; may be null if unknown
	BackgroundType BackgroundTypeClass
}

// LinkPreviewTypeBackgroundTypeID is TL type id of LinkPreviewTypeBackground.
const LinkPreviewTypeBackgroundTypeID = 0x3a48a1e0

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeBackground) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeBackground{}
)

func (l *LinkPreviewTypeBackground) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Document.Zero()) {
		return false
	}
	if !(l.BackgroundType == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeBackground) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeBackground",
		ID:   LinkPreviewTypeBackgroundTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Document",
			SchemaName: "document",
		},
		{
			Name:       "BackgroundType",
			SchemaName: "background_type",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeBackground) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeBackground#3a48a1e0 as nil")
	}
	b.PutID(LinkPreviewTypeBackgroundTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeBackground) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeBackground#3a48a1e0 as nil")
	}
	if err := l.Document.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeBackground#3a48a1e0: field document: %w", err)
	}
	if l.BackgroundType == nil {
		return fmt.Errorf("unable to encode linkPreviewTypeBackground#3a48a1e0: field background_type is nil")
	}
	if err := l.BackgroundType.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeBackground#3a48a1e0: field background_type: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeBackground) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeBackground#3a48a1e0 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeBackgroundTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeBackground#3a48a1e0: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeBackground) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeBackground#3a48a1e0 to nil")
	}
	{
		if err := l.Document.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeBackground#3a48a1e0: field document: %w", err)
		}
	}
	{
		value, err := DecodeBackgroundType(b)
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeBackground#3a48a1e0: field background_type: %w", err)
		}
		l.BackgroundType = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeBackground) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeBackground#3a48a1e0 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeBackground")
	b.Comma()
	b.FieldStart("document")
	if err := l.Document.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeBackground#3a48a1e0: field document: %w", err)
	}
	b.Comma()
	b.FieldStart("background_type")
	if l.BackgroundType == nil {
		return fmt.Errorf("unable to encode linkPreviewTypeBackground#3a48a1e0: field background_type is nil")
	}
	if err := l.BackgroundType.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeBackground#3a48a1e0: field background_type: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeBackground) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeBackground#3a48a1e0 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeBackground"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeBackground#3a48a1e0: %w", err)
			}
		case "document":
			if err := l.Document.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeBackground#3a48a1e0: field document: %w", err)
			}
		case "background_type":
			value, err := DecodeTDLibJSONBackgroundType(b)
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeBackground#3a48a1e0: field background_type: %w", err)
			}
			l.BackgroundType = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetDocument returns value of Document field.
func (l *LinkPreviewTypeBackground) GetDocument() (value Document) {
	if l == nil {
		return
	}
	return l.Document
}

// GetBackgroundType returns value of BackgroundType field.
func (l *LinkPreviewTypeBackground) GetBackgroundType() (value BackgroundTypeClass) {
	if l == nil {
		return
	}
	return l.BackgroundType
}

// LinkPreviewTypeChannelBoost represents TL type `linkPreviewTypeChannelBoost#c6f40456`.
type LinkPreviewTypeChannelBoost struct {
	// Photo of the chat; may be null
	Photo ChatPhoto
}

// LinkPreviewTypeChannelBoostTypeID is TL type id of LinkPreviewTypeChannelBoost.
const LinkPreviewTypeChannelBoostTypeID = 0xc6f40456

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeChannelBoost) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeChannelBoost{}
)

func (l *LinkPreviewTypeChannelBoost) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeChannelBoost) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeChannelBoost",
		ID:   LinkPreviewTypeChannelBoostTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeChannelBoost) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeChannelBoost#c6f40456 as nil")
	}
	b.PutID(LinkPreviewTypeChannelBoostTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeChannelBoost) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeChannelBoost#c6f40456 as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChannelBoost#c6f40456: field photo: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeChannelBoost) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeChannelBoost#c6f40456 to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeChannelBoost#c6f40456: field photo: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeChannelBoost) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeChannelBoost#c6f40456 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeChannelBoost")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChannelBoost#c6f40456: field photo: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeChannelBoost) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeChannelBoost#c6f40456 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeChannelBoost"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeChannelBoost#c6f40456: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeChannelBoost#c6f40456: field photo: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeChannelBoost) GetPhoto() (value ChatPhoto) {
	if l == nil {
		return
	}
	return l.Photo
}

// LinkPreviewTypeChat represents TL type `linkPreviewTypeChat#ae2fa122`.
type LinkPreviewTypeChat struct {
	// Type of the chat
	Type InviteLinkChatTypeClass
	// Photo of the chat; may be null
	Photo ChatPhoto
	// True, if the link only creates join request
	CreatesJoinRequest bool
}

// LinkPreviewTypeChatTypeID is TL type id of LinkPreviewTypeChat.
const LinkPreviewTypeChatTypeID = 0xae2fa122

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeChat) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeChat{}
)

func (l *LinkPreviewTypeChat) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Type == nil) {
		return false
	}
	if !(l.Photo.Zero()) {
		return false
	}
	if !(l.CreatesJoinRequest == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeChat) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeChat",
		ID:   LinkPreviewTypeChatTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Type",
			SchemaName: "type",
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
		{
			Name:       "CreatesJoinRequest",
			SchemaName: "creates_join_request",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeChat) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeChat#ae2fa122 as nil")
	}
	b.PutID(LinkPreviewTypeChatTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeChat) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeChat#ae2fa122 as nil")
	}
	if l.Type == nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChat#ae2fa122: field type is nil")
	}
	if err := l.Type.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChat#ae2fa122: field type: %w", err)
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChat#ae2fa122: field photo: %w", err)
	}
	b.PutBool(l.CreatesJoinRequest)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeChat) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeChat#ae2fa122 to nil")
	}
	{
		value, err := DecodeInviteLinkChatType(b)
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: field type: %w", err)
		}
		l.Type = value
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: field photo: %w", err)
		}
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: field creates_join_request: %w", err)
		}
		l.CreatesJoinRequest = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeChat) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeChat#ae2fa122 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeChat")
	b.Comma()
	b.FieldStart("type")
	if l.Type == nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChat#ae2fa122: field type is nil")
	}
	if err := l.Type.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChat#ae2fa122: field type: %w", err)
	}
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeChat#ae2fa122: field photo: %w", err)
	}
	b.Comma()
	b.FieldStart("creates_join_request")
	b.PutBool(l.CreatesJoinRequest)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeChat) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeChat#ae2fa122 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeChat"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: %w", err)
			}
		case "type":
			value, err := DecodeTDLibJSONInviteLinkChatType(b)
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: field type: %w", err)
			}
			l.Type = value
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: field photo: %w", err)
			}
		case "creates_join_request":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeChat#ae2fa122: field creates_join_request: %w", err)
			}
			l.CreatesJoinRequest = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetType returns value of Type field.
func (l *LinkPreviewTypeChat) GetType() (value InviteLinkChatTypeClass) {
	if l == nil {
		return
	}
	return l.Type
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeChat) GetPhoto() (value ChatPhoto) {
	if l == nil {
		return
	}
	return l.Photo
}

// GetCreatesJoinRequest returns value of CreatesJoinRequest field.
func (l *LinkPreviewTypeChat) GetCreatesJoinRequest() (value bool) {
	if l == nil {
		return
	}
	return l.CreatesJoinRequest
}

// LinkPreviewTypeDocument represents TL type `linkPreviewTypeDocument#bf0169a2`.
type LinkPreviewTypeDocument struct {
	// The document description
	Document Document
}

// LinkPreviewTypeDocumentTypeID is TL type id of LinkPreviewTypeDocument.
const LinkPreviewTypeDocumentTypeID = 0xbf0169a2

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeDocument) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeDocument{}
)

func (l *LinkPreviewTypeDocument) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Document.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeDocument) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeDocument",
		ID:   LinkPreviewTypeDocumentTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Document",
			SchemaName: "document",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeDocument) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeDocument#bf0169a2 as nil")
	}
	b.PutID(LinkPreviewTypeDocumentTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeDocument) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeDocument#bf0169a2 as nil")
	}
	if err := l.Document.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeDocument#bf0169a2: field document: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeDocument) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeDocument#bf0169a2 to nil")
	}
	{
		if err := l.Document.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeDocument#bf0169a2: field document: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeDocument) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeDocument#bf0169a2 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeDocument")
	b.Comma()
	b.FieldStart("document")
	if err := l.Document.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeDocument#bf0169a2: field document: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeDocument) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeDocument#bf0169a2 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeDocument"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeDocument#bf0169a2: %w", err)
			}
		case "document":
			if err := l.Document.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeDocument#bf0169a2: field document: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetDocument returns value of Document field.
func (l *LinkPreviewTypeDocument) GetDocument() (value Document) {
	if l == nil {
		return
	}
	return l.Document
}

// LinkPreviewTypeEmbeddedAnimationPlayer represents TL type `linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605`.
type LinkPreviewTypeEmbeddedAnimationPlayer struct {
	// URL of the external animation player
	URL string
	// Thumbnail of the animation; may be null if unknown
	Thumbnail Photo
	// Duration of the animation, in seconds
	Duration int32
	// Expected width of the embedded player
	Width int32
	// Expected height of the embedded player
	Height int32
}

// LinkPreviewTypeEmbeddedAnimationPlayerTypeID is TL type id of LinkPreviewTypeEmbeddedAnimationPlayer.
const LinkPreviewTypeEmbeddedAnimationPlayerTypeID = 0xaa5ad605

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeEmbeddedAnimationPlayer) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeEmbeddedAnimationPlayer{}
)

func (l *LinkPreviewTypeEmbeddedAnimationPlayer) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.URL == "") {
		return false
	}
	if !(l.Thumbnail.Zero()) {
		return false
	}
	if !(l.Duration == 0) {
		return false
	}
	if !(l.Width == 0) {
		return false
	}
	if !(l.Height == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeEmbeddedAnimationPlayer",
		ID:   LinkPreviewTypeEmbeddedAnimationPlayerTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Thumbnail",
			SchemaName: "thumbnail",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
		{
			Name:       "Width",
			SchemaName: "width",
		},
		{
			Name:       "Height",
			SchemaName: "height",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605 as nil")
	}
	b.PutID(LinkPreviewTypeEmbeddedAnimationPlayerTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605 as nil")
	}
	b.PutString(l.URL)
	if err := l.Thumbnail.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field thumbnail: %w", err)
	}
	b.PutInt32(l.Duration)
	b.PutInt32(l.Width)
	b.PutInt32(l.Height)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field url: %w", err)
		}
		l.URL = value
	}
	{
		if err := l.Thumbnail.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field thumbnail: %w", err)
		}
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field duration: %w", err)
		}
		l.Duration = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field width: %w", err)
		}
		l.Width = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field height: %w", err)
		}
		l.Height = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeEmbeddedAnimationPlayer")
	b.Comma()
	b.FieldStart("url")
	b.PutString(l.URL)
	b.Comma()
	b.FieldStart("thumbnail")
	if err := l.Thumbnail.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field thumbnail: %w", err)
	}
	b.Comma()
	b.FieldStart("duration")
	b.PutInt32(l.Duration)
	b.Comma()
	b.FieldStart("width")
	b.PutInt32(l.Width)
	b.Comma()
	b.FieldStart("height")
	b.PutInt32(l.Height)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeEmbeddedAnimationPlayer"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: %w", err)
			}
		case "url":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field url: %w", err)
			}
			l.URL = value
		case "thumbnail":
			if err := l.Thumbnail.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field thumbnail: %w", err)
			}
		case "duration":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field duration: %w", err)
			}
			l.Duration = value
		case "width":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field width: %w", err)
			}
			l.Width = value
		case "height":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605: field height: %w", err)
			}
			l.Height = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetURL returns value of URL field.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) GetURL() (value string) {
	if l == nil {
		return
	}
	return l.URL
}

// GetThumbnail returns value of Thumbnail field.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) GetThumbnail() (value Photo) {
	if l == nil {
		return
	}
	return l.Thumbnail
}

// GetDuration returns value of Duration field.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) GetDuration() (value int32) {
	if l == nil {
		return
	}
	return l.Duration
}

// GetWidth returns value of Width field.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) GetWidth() (value int32) {
	if l == nil {
		return
	}
	return l.Width
}

// GetHeight returns value of Height field.
func (l *LinkPreviewTypeEmbeddedAnimationPlayer) GetHeight() (value int32) {
	if l == nil {
		return
	}
	return l.Height
}

// LinkPreviewTypeEmbeddedAudioPlayer represents TL type `linkPreviewTypeEmbeddedAudioPlayer#220b429c`.
type LinkPreviewTypeEmbeddedAudioPlayer struct {
	// URL of the external audio player
	URL string
	// Thumbnail of the audio; may be null if unknown
	Thumbnail Photo
	// Duration of the audio, in seconds
	Duration int32
	// Expected width of the embedded player
	Width int32
	// Expected height of the embedded player
	Height int32
}

// LinkPreviewTypeEmbeddedAudioPlayerTypeID is TL type id of LinkPreviewTypeEmbeddedAudioPlayer.
const LinkPreviewTypeEmbeddedAudioPlayerTypeID = 0x220b429c

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeEmbeddedAudioPlayer) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeEmbeddedAudioPlayer{}
)

func (l *LinkPreviewTypeEmbeddedAudioPlayer) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.URL == "") {
		return false
	}
	if !(l.Thumbnail.Zero()) {
		return false
	}
	if !(l.Duration == 0) {
		return false
	}
	if !(l.Width == 0) {
		return false
	}
	if !(l.Height == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeEmbeddedAudioPlayer",
		ID:   LinkPreviewTypeEmbeddedAudioPlayerTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Thumbnail",
			SchemaName: "thumbnail",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
		{
			Name:       "Width",
			SchemaName: "width",
		},
		{
			Name:       "Height",
			SchemaName: "height",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedAudioPlayer#220b429c as nil")
	}
	b.PutID(LinkPreviewTypeEmbeddedAudioPlayerTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedAudioPlayer#220b429c as nil")
	}
	b.PutString(l.URL)
	if err := l.Thumbnail.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field thumbnail: %w", err)
	}
	b.PutInt32(l.Duration)
	b.PutInt32(l.Width)
	b.PutInt32(l.Height)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedAudioPlayer#220b429c to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeEmbeddedAudioPlayerTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedAudioPlayer#220b429c to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field url: %w", err)
		}
		l.URL = value
	}
	{
		if err := l.Thumbnail.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field thumbnail: %w", err)
		}
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field duration: %w", err)
		}
		l.Duration = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field width: %w", err)
		}
		l.Width = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field height: %w", err)
		}
		l.Height = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedAudioPlayer#220b429c as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeEmbeddedAudioPlayer")
	b.Comma()
	b.FieldStart("url")
	b.PutString(l.URL)
	b.Comma()
	b.FieldStart("thumbnail")
	if err := l.Thumbnail.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field thumbnail: %w", err)
	}
	b.Comma()
	b.FieldStart("duration")
	b.PutInt32(l.Duration)
	b.Comma()
	b.FieldStart("width")
	b.PutInt32(l.Width)
	b.Comma()
	b.FieldStart("height")
	b.PutInt32(l.Height)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedAudioPlayer#220b429c to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeEmbeddedAudioPlayer"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: %w", err)
			}
		case "url":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field url: %w", err)
			}
			l.URL = value
		case "thumbnail":
			if err := l.Thumbnail.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field thumbnail: %w", err)
			}
		case "duration":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field duration: %w", err)
			}
			l.Duration = value
		case "width":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field width: %w", err)
			}
			l.Width = value
		case "height":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedAudioPlayer#220b429c: field height: %w", err)
			}
			l.Height = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetURL returns value of URL field.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) GetURL() (value string) {
	if l == nil {
		return
	}
	return l.URL
}

// GetThumbnail returns value of Thumbnail field.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) GetThumbnail() (value Photo) {
	if l == nil {
		return
	}
	return l.Thumbnail
}

// GetDuration returns value of Duration field.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) GetDuration() (value int32) {
	if l == nil {
		return
	}
	return l.Duration
}

// GetWidth returns value of Width field.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) GetWidth() (value int32) {
	if l == nil {
		return
	}
	return l.Width
}

// GetHeight returns value of Height field.
func (l *LinkPreviewTypeEmbeddedAudioPlayer) GetHeight() (value int32) {
	if l == nil {
		return
	}
	return l.Height
}

// LinkPreviewTypeEmbeddedVideoPlayer represents TL type `linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03`.
type LinkPreviewTypeEmbeddedVideoPlayer struct {
	// URL of the external video player
	URL string
	// Thumbnail of the video; may be null if unknown
	Thumbnail Photo
	// Duration of the video, in seconds
	Duration int32
	// Expected width of the embedded player
	Width int32
	// Expected height of the embedded player
	Height int32
}

// LinkPreviewTypeEmbeddedVideoPlayerTypeID is TL type id of LinkPreviewTypeEmbeddedVideoPlayer.
const LinkPreviewTypeEmbeddedVideoPlayerTypeID = 0xa7bfbb03

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeEmbeddedVideoPlayer) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeEmbeddedVideoPlayer{}
)

func (l *LinkPreviewTypeEmbeddedVideoPlayer) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.URL == "") {
		return false
	}
	if !(l.Thumbnail.Zero()) {
		return false
	}
	if !(l.Duration == 0) {
		return false
	}
	if !(l.Width == 0) {
		return false
	}
	if !(l.Height == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeEmbeddedVideoPlayer",
		ID:   LinkPreviewTypeEmbeddedVideoPlayerTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Thumbnail",
			SchemaName: "thumbnail",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
		{
			Name:       "Width",
			SchemaName: "width",
		},
		{
			Name:       "Height",
			SchemaName: "height",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03 as nil")
	}
	b.PutID(LinkPreviewTypeEmbeddedVideoPlayerTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03 as nil")
	}
	b.PutString(l.URL)
	if err := l.Thumbnail.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field thumbnail: %w", err)
	}
	b.PutInt32(l.Duration)
	b.PutInt32(l.Width)
	b.PutInt32(l.Height)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field url: %w", err)
		}
		l.URL = value
	}
	{
		if err := l.Thumbnail.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field thumbnail: %w", err)
		}
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field duration: %w", err)
		}
		l.Duration = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field width: %w", err)
		}
		l.Width = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field height: %w", err)
		}
		l.Height = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeEmbeddedVideoPlayer")
	b.Comma()
	b.FieldStart("url")
	b.PutString(l.URL)
	b.Comma()
	b.FieldStart("thumbnail")
	if err := l.Thumbnail.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field thumbnail: %w", err)
	}
	b.Comma()
	b.FieldStart("duration")
	b.PutInt32(l.Duration)
	b.Comma()
	b.FieldStart("width")
	b.PutInt32(l.Width)
	b.Comma()
	b.FieldStart("height")
	b.PutInt32(l.Height)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeEmbeddedVideoPlayer"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: %w", err)
			}
		case "url":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field url: %w", err)
			}
			l.URL = value
		case "thumbnail":
			if err := l.Thumbnail.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field thumbnail: %w", err)
			}
		case "duration":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field duration: %w", err)
			}
			l.Duration = value
		case "width":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field width: %w", err)
			}
			l.Width = value
		case "height":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03: field height: %w", err)
			}
			l.Height = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetURL returns value of URL field.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) GetURL() (value string) {
	if l == nil {
		return
	}
	return l.URL
}

// GetThumbnail returns value of Thumbnail field.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) GetThumbnail() (value Photo) {
	if l == nil {
		return
	}
	return l.Thumbnail
}

// GetDuration returns value of Duration field.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) GetDuration() (value int32) {
	if l == nil {
		return
	}
	return l.Duration
}

// GetWidth returns value of Width field.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) GetWidth() (value int32) {
	if l == nil {
		return
	}
	return l.Width
}

// GetHeight returns value of Height field.
func (l *LinkPreviewTypeEmbeddedVideoPlayer) GetHeight() (value int32) {
	if l == nil {
		return
	}
	return l.Height
}

// LinkPreviewTypeExternalAudio represents TL type `linkPreviewTypeExternalAudio#8a82ffed`.
type LinkPreviewTypeExternalAudio struct {
	// URL of the audio file
	URL string
	// MIME type of the audio file
	MimeType string
	// Duration of the audio, in seconds; 0 if unknown
	Duration int32
}

// LinkPreviewTypeExternalAudioTypeID is TL type id of LinkPreviewTypeExternalAudio.
const LinkPreviewTypeExternalAudioTypeID = 0x8a82ffed

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeExternalAudio) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeExternalAudio{}
)

func (l *LinkPreviewTypeExternalAudio) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.URL == "") {
		return false
	}
	if !(l.MimeType == "") {
		return false
	}
	if !(l.Duration == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeExternalAudio) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeExternalAudio",
		ID:   LinkPreviewTypeExternalAudioTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "MimeType",
			SchemaName: "mime_type",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeExternalAudio) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeExternalAudio#8a82ffed as nil")
	}
	b.PutID(LinkPreviewTypeExternalAudioTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeExternalAudio) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeExternalAudio#8a82ffed as nil")
	}
	b.PutString(l.URL)
	b.PutString(l.MimeType)
	b.PutInt32(l.Duration)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeExternalAudio) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeExternalAudio#8a82ffed to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeExternalAudioTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeExternalAudio) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeExternalAudio#8a82ffed to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: field url: %w", err)
		}
		l.URL = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: field mime_type: %w", err)
		}
		l.MimeType = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: field duration: %w", err)
		}
		l.Duration = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeExternalAudio) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeExternalAudio#8a82ffed as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeExternalAudio")
	b.Comma()
	b.FieldStart("url")
	b.PutString(l.URL)
	b.Comma()
	b.FieldStart("mime_type")
	b.PutString(l.MimeType)
	b.Comma()
	b.FieldStart("duration")
	b.PutInt32(l.Duration)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeExternalAudio) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeExternalAudio#8a82ffed to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeExternalAudio"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: %w", err)
			}
		case "url":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: field url: %w", err)
			}
			l.URL = value
		case "mime_type":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: field mime_type: %w", err)
			}
			l.MimeType = value
		case "duration":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalAudio#8a82ffed: field duration: %w", err)
			}
			l.Duration = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetURL returns value of URL field.
func (l *LinkPreviewTypeExternalAudio) GetURL() (value string) {
	if l == nil {
		return
	}
	return l.URL
}

// GetMimeType returns value of MimeType field.
func (l *LinkPreviewTypeExternalAudio) GetMimeType() (value string) {
	if l == nil {
		return
	}
	return l.MimeType
}

// GetDuration returns value of Duration field.
func (l *LinkPreviewTypeExternalAudio) GetDuration() (value int32) {
	if l == nil {
		return
	}
	return l.Duration
}

// LinkPreviewTypeExternalVideo represents TL type `linkPreviewTypeExternalVideo#517dcb98`.
type LinkPreviewTypeExternalVideo struct {
	// URL of the video file
	URL string
	// MIME type of the video file
	MimeType string
	// Expected width of the video preview; 0 if unknown
	Width int32
	// Expected height of the video preview; 0 if unknown
	Height int32
	// Duration of the video, in seconds; 0 if unknown
	Duration int32
}

// LinkPreviewTypeExternalVideoTypeID is TL type id of LinkPreviewTypeExternalVideo.
const LinkPreviewTypeExternalVideoTypeID = 0x517dcb98

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeExternalVideo) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeExternalVideo{}
)

func (l *LinkPreviewTypeExternalVideo) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.URL == "") {
		return false
	}
	if !(l.MimeType == "") {
		return false
	}
	if !(l.Width == 0) {
		return false
	}
	if !(l.Height == 0) {
		return false
	}
	if !(l.Duration == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeExternalVideo) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeExternalVideo",
		ID:   LinkPreviewTypeExternalVideoTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "MimeType",
			SchemaName: "mime_type",
		},
		{
			Name:       "Width",
			SchemaName: "width",
		},
		{
			Name:       "Height",
			SchemaName: "height",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeExternalVideo) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeExternalVideo#517dcb98 as nil")
	}
	b.PutID(LinkPreviewTypeExternalVideoTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeExternalVideo) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeExternalVideo#517dcb98 as nil")
	}
	b.PutString(l.URL)
	b.PutString(l.MimeType)
	b.PutInt32(l.Width)
	b.PutInt32(l.Height)
	b.PutInt32(l.Duration)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeExternalVideo) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeExternalVideo#517dcb98 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeExternalVideoTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeExternalVideo) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeExternalVideo#517dcb98 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field url: %w", err)
		}
		l.URL = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field mime_type: %w", err)
		}
		l.MimeType = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field width: %w", err)
		}
		l.Width = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field height: %w", err)
		}
		l.Height = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field duration: %w", err)
		}
		l.Duration = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeExternalVideo) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeExternalVideo#517dcb98 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeExternalVideo")
	b.Comma()
	b.FieldStart("url")
	b.PutString(l.URL)
	b.Comma()
	b.FieldStart("mime_type")
	b.PutString(l.MimeType)
	b.Comma()
	b.FieldStart("width")
	b.PutInt32(l.Width)
	b.Comma()
	b.FieldStart("height")
	b.PutInt32(l.Height)
	b.Comma()
	b.FieldStart("duration")
	b.PutInt32(l.Duration)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeExternalVideo) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeExternalVideo#517dcb98 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeExternalVideo"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: %w", err)
			}
		case "url":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field url: %w", err)
			}
			l.URL = value
		case "mime_type":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field mime_type: %w", err)
			}
			l.MimeType = value
		case "width":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field width: %w", err)
			}
			l.Width = value
		case "height":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field height: %w", err)
			}
			l.Height = value
		case "duration":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeExternalVideo#517dcb98: field duration: %w", err)
			}
			l.Duration = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetURL returns value of URL field.
func (l *LinkPreviewTypeExternalVideo) GetURL() (value string) {
	if l == nil {
		return
	}
	return l.URL
}

// GetMimeType returns value of MimeType field.
func (l *LinkPreviewTypeExternalVideo) GetMimeType() (value string) {
	if l == nil {
		return
	}
	return l.MimeType
}

// GetWidth returns value of Width field.
func (l *LinkPreviewTypeExternalVideo) GetWidth() (value int32) {
	if l == nil {
		return
	}
	return l.Width
}

// GetHeight returns value of Height field.
func (l *LinkPreviewTypeExternalVideo) GetHeight() (value int32) {
	if l == nil {
		return
	}
	return l.Height
}

// GetDuration returns value of Duration field.
func (l *LinkPreviewTypeExternalVideo) GetDuration() (value int32) {
	if l == nil {
		return
	}
	return l.Duration
}

// LinkPreviewTypeGroupCall represents TL type `linkPreviewTypeGroupCall#b5f190e0`.
type LinkPreviewTypeGroupCall struct {
}

// LinkPreviewTypeGroupCallTypeID is TL type id of LinkPreviewTypeGroupCall.
const LinkPreviewTypeGroupCallTypeID = 0xb5f190e0

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeGroupCall) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeGroupCall{}
)

func (l *LinkPreviewTypeGroupCall) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeGroupCall) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeGroupCall",
		ID:   LinkPreviewTypeGroupCallTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeGroupCall) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeGroupCall#b5f190e0 as nil")
	}
	b.PutID(LinkPreviewTypeGroupCallTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeGroupCall) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeGroupCall#b5f190e0 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeGroupCall) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeGroupCall#b5f190e0 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeGroupCall) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeGroupCall#b5f190e0 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeGroupCall")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeGroupCall) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeGroupCall#b5f190e0 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeGroupCall"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeGroupCall#b5f190e0: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// LinkPreviewTypeInvoice represents TL type `linkPreviewTypeInvoice#d47f48da`.
type LinkPreviewTypeInvoice struct {
}

// LinkPreviewTypeInvoiceTypeID is TL type id of LinkPreviewTypeInvoice.
const LinkPreviewTypeInvoiceTypeID = 0xd47f48da

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeInvoice) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeInvoice{}
)

func (l *LinkPreviewTypeInvoice) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeInvoice) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeInvoice",
		ID:   LinkPreviewTypeInvoiceTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeInvoice) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeInvoice#d47f48da as nil")
	}
	b.PutID(LinkPreviewTypeInvoiceTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeInvoice) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeInvoice#d47f48da as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeInvoice) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeInvoice#d47f48da to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeInvoice) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeInvoice#d47f48da as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeInvoice")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeInvoice) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeInvoice#d47f48da to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeInvoice"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeInvoice#d47f48da: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// LinkPreviewTypeMessage represents TL type `linkPreviewTypeMessage#19f4c19e`.
type LinkPreviewTypeMessage struct {
}

// LinkPreviewTypeMessageTypeID is TL type id of LinkPreviewTypeMessage.
const LinkPreviewTypeMessageTypeID = 0x19f4c19e

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeMessage) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeMessage{}
)

func (l *LinkPreviewTypeMessage) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeMessage) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeMessage",
		ID:   LinkPreviewTypeMessageTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeMessage) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeMessage#19f4c19e as nil")
	}
	b.PutID(LinkPreviewTypeMessageTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeMessage) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeMessage#19f4c19e as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeMessage) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeMessage#19f4c19e to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeMessageTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeMessage#19f4c19e: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeMessage) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeMessage#19f4c19e to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeMessage) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeMessage#19f4c19e as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeMessage")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeMessage) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeMessage#19f4c19e to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeMessage"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeMessage#19f4c19e: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// LinkPreviewTypePhoto represents TL type `linkPreviewTypePhoto#aecfaaac`.
type LinkPreviewTypePhoto struct {
	// The photo
	Photo Photo
}

// LinkPreviewTypePhotoTypeID is TL type id of LinkPreviewTypePhoto.
const LinkPreviewTypePhotoTypeID = 0xaecfaaac

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypePhoto) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypePhoto{}
)

func (l *LinkPreviewTypePhoto) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypePhoto) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypePhoto",
		ID:   LinkPreviewTypePhotoTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypePhoto) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypePhoto#aecfaaac as nil")
	}
	b.PutID(LinkPreviewTypePhotoTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypePhoto) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypePhoto#aecfaaac as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypePhoto#aecfaaac: field photo: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypePhoto) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypePhoto#aecfaaac to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypePhoto#aecfaaac: field photo: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypePhoto) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypePhoto#aecfaaac as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypePhoto")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypePhoto#aecfaaac: field photo: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypePhoto) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypePhoto#aecfaaac to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypePhoto"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypePhoto#aecfaaac: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypePhoto#aecfaaac: field photo: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypePhoto) GetPhoto() (value Photo) {
	if l == nil {
		return
	}
	return l.Photo
}

// LinkPreviewTypePremiumGiftCode represents TL type `linkPreviewTypePremiumGiftCode#4e0d80b1`.
type LinkPreviewTypePremiumGiftCode struct {
}

// LinkPreviewTypePremiumGiftCodeTypeID is TL type id of LinkPreviewTypePremiumGiftCode.
const LinkPreviewTypePremiumGiftCodeTypeID = 0x4e0d80b1

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypePremiumGiftCode) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypePremiumGiftCode{}
)

func (l *LinkPreviewTypePremiumGiftCode) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypePremiumGiftCode) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypePremiumGiftCode",
		ID:   LinkPreviewTypePremiumGiftCodeTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypePremiumGiftCode) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypePremiumGiftCode#4e0d80b1 as nil")
	}
	b.PutID(LinkPreviewTypePremiumGiftCodeTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypePremiumGiftCode) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypePremiumGiftCode#4e0d80b1 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypePremiumGiftCode) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypePremiumGiftCode#4e0d80b1 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypePremiumGiftCodeTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypePremiumGiftCode#4e0d80b1: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypePremiumGiftCode) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypePremiumGiftCode#4e0d80b1 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypePremiumGiftCode) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypePremiumGiftCode#4e0d80b1 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypePremiumGiftCode")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypePremiumGiftCode) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypePremiumGiftCode#4e0d80b1 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypePremiumGiftCode"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypePremiumGiftCode#4e0d80b1: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// LinkPreviewTypeShareableChatFolder represents TL type `linkPreviewTypeShareableChatFolder#805ab33c`.
type LinkPreviewTypeShareableChatFolder struct {
}

// LinkPreviewTypeShareableChatFolderTypeID is TL type id of LinkPreviewTypeShareableChatFolder.
const LinkPreviewTypeShareableChatFolderTypeID = 0x805ab33c

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeShareableChatFolder) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeShareableChatFolder{}
)

func (l *LinkPreviewTypeShareableChatFolder) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeShareableChatFolder) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeShareableChatFolder",
		ID:   LinkPreviewTypeShareableChatFolderTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeShareableChatFolder) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeShareableChatFolder#805ab33c as nil")
	}
	b.PutID(LinkPreviewTypeShareableChatFolderTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeShareableChatFolder) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeShareableChatFolder#805ab33c as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeShareableChatFolder) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeShareableChatFolder#805ab33c to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeShareableChatFolderTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeShareableChatFolder#805ab33c: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeShareableChatFolder) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeShareableChatFolder#805ab33c to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeShareableChatFolder) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeShareableChatFolder#805ab33c as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeShareableChatFolder")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeShareableChatFolder) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeShareableChatFolder#805ab33c to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeShareableChatFolder"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeShareableChatFolder#805ab33c: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// LinkPreviewTypeSticker represents TL type `linkPreviewTypeSticker#245f4d25`.
type LinkPreviewTypeSticker struct {
	// The sticker. It can be an arbitrary WEBP image and can have dimensions bigger than 512
	Sticker Sticker
}

// LinkPreviewTypeStickerTypeID is TL type id of LinkPreviewTypeSticker.
const LinkPreviewTypeStickerTypeID = 0x245f4d25

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeSticker) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeSticker{}
)

func (l *LinkPreviewTypeSticker) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Sticker.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeSticker) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeSticker",
		ID:   LinkPreviewTypeStickerTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Sticker",
			SchemaName: "sticker",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeSticker) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeSticker#245f4d25 as nil")
	}
	b.PutID(LinkPreviewTypeStickerTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeSticker) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeSticker#245f4d25 as nil")
	}
	if err := l.Sticker.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeSticker#245f4d25: field sticker: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeSticker) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeSticker#245f4d25 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeStickerTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeSticker#245f4d25: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeSticker) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeSticker#245f4d25 to nil")
	}
	{
		if err := l.Sticker.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeSticker#245f4d25: field sticker: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeSticker) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeSticker#245f4d25 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeSticker")
	b.Comma()
	b.FieldStart("sticker")
	if err := l.Sticker.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeSticker#245f4d25: field sticker: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeSticker) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeSticker#245f4d25 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeSticker"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeSticker#245f4d25: %w", err)
			}
		case "sticker":
			if err := l.Sticker.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeSticker#245f4d25: field sticker: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSticker returns value of Sticker field.
func (l *LinkPreviewTypeSticker) GetSticker() (value Sticker) {
	if l == nil {
		return
	}
	return l.Sticker
}

// LinkPreviewTypeStickerSet represents TL type `linkPreviewTypeStickerSet#cb82a523`.
type LinkPreviewTypeStickerSet struct {
	// Up to 4 stickers from the sticker set
	Stickers []Sticker
}

// LinkPreviewTypeStickerSetTypeID is TL type id of LinkPreviewTypeStickerSet.
const LinkPreviewTypeStickerSetTypeID = 0xcb82a523

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeStickerSet) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeStickerSet{}
)

func (l *LinkPreviewTypeStickerSet) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Stickers == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeStickerSet) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeStickerSet",
		ID:   LinkPreviewTypeStickerSetTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Stickers",
			SchemaName: "stickers",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeStickerSet) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeStickerSet#cb82a523 as nil")
	}
	b.PutID(LinkPreviewTypeStickerSetTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeStickerSet) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeStickerSet#cb82a523 as nil")
	}
	b.PutInt(len(l.Stickers))
	for idx, v := range l.Stickers {
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare linkPreviewTypeStickerSet#cb82a523: field stickers element with index %d: %w", idx, err)
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeStickerSet) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeStickerSet#cb82a523 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeStickerSet#cb82a523: field stickers: %w", err)
		}

		if headerLen > 0 {
			l.Stickers = make([]Sticker, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value Sticker
			if err := value.DecodeBare(b); err != nil {
				return fmt.Errorf("unable to decode bare linkPreviewTypeStickerSet#cb82a523: field stickers: %w", err)
			}
			l.Stickers = append(l.Stickers, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeStickerSet) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeStickerSet#cb82a523 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeStickerSet")
	b.Comma()
	b.FieldStart("stickers")
	b.ArrStart()
	for idx, v := range l.Stickers {
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode linkPreviewTypeStickerSet#cb82a523: field stickers element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeStickerSet) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeStickerSet#cb82a523 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeStickerSet"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeStickerSet#cb82a523: %w", err)
			}
		case "stickers":
			if err := b.Arr(func(b tdjson.Decoder) error {
				var value Sticker
				if err := value.DecodeTDLibJSON(b); err != nil {
					return fmt.Errorf("unable to decode linkPreviewTypeStickerSet#cb82a523: field stickers: %w", err)
				}
				l.Stickers = append(l.Stickers, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeStickerSet#cb82a523: field stickers: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetStickers returns value of Stickers field.
func (l *LinkPreviewTypeStickerSet) GetStickers() (value []Sticker) {
	if l == nil {
		return
	}
	return l.Stickers
}

// LinkPreviewTypeStory represents TL type `linkPreviewTypeStory#3e5442db`.
type LinkPreviewTypeStory struct {
	// The identifier of the chat that posted the story
	StoryPosterChatID int64
	// Story identifier
	StoryID int32
}

// LinkPreviewTypeStoryTypeID is TL type id of LinkPreviewTypeStory.
const LinkPreviewTypeStoryTypeID = 0x3e5442db

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeStory) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeStory{}
)

func (l *LinkPreviewTypeStory) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.StoryPosterChatID == 0) {
		return false
	}
	if !(l.StoryID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeStory) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeStory",
		ID:   LinkPreviewTypeStoryTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "StoryPosterChatID",
			SchemaName: "story_poster_chat_id",
		},
		{
			Name:       "StoryID",
			SchemaName: "story_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeStory) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeStory#3e5442db as nil")
	}
	b.PutID(LinkPreviewTypeStoryTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeStory) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeStory#3e5442db as nil")
	}
	b.PutInt53(l.StoryPosterChatID)
	b.PutInt32(l.StoryID)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeStory) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeStory#3e5442db to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeStoryTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeStory#3e5442db: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeStory) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeStory#3e5442db to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeStory#3e5442db: field story_poster_chat_id: %w", err)
		}
		l.StoryPosterChatID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeStory#3e5442db: field story_id: %w", err)
		}
		l.StoryID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeStory) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeStory#3e5442db as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeStory")
	b.Comma()
	b.FieldStart("story_poster_chat_id")
	b.PutInt53(l.StoryPosterChatID)
	b.Comma()
	b.FieldStart("story_id")
	b.PutInt32(l.StoryID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeStory) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeStory#3e5442db to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeStory"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeStory#3e5442db: %w", err)
			}
		case "story_poster_chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeStory#3e5442db: field story_poster_chat_id: %w", err)
			}
			l.StoryPosterChatID = value
		case "story_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeStory#3e5442db: field story_id: %w", err)
			}
			l.StoryID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetStoryPosterChatID returns value of StoryPosterChatID field.
func (l *LinkPreviewTypeStory) GetStoryPosterChatID() (value int64) {
	if l == nil {
		return
	}
	return l.StoryPosterChatID
}

// GetStoryID returns value of StoryID field.
func (l *LinkPreviewTypeStory) GetStoryID() (value int32) {
	if l == nil {
		return
	}
	return l.StoryID
}

// LinkPreviewTypeSupergroupBoost represents TL type `linkPreviewTypeSupergroupBoost#90570476`.
type LinkPreviewTypeSupergroupBoost struct {
	// Photo of the chat; may be null
	Photo ChatPhoto
}

// LinkPreviewTypeSupergroupBoostTypeID is TL type id of LinkPreviewTypeSupergroupBoost.
const LinkPreviewTypeSupergroupBoostTypeID = 0x90570476

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeSupergroupBoost) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeSupergroupBoost{}
)

func (l *LinkPreviewTypeSupergroupBoost) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeSupergroupBoost) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeSupergroupBoost",
		ID:   LinkPreviewTypeSupergroupBoostTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeSupergroupBoost) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeSupergroupBoost#90570476 as nil")
	}
	b.PutID(LinkPreviewTypeSupergroupBoostTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeSupergroupBoost) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeSupergroupBoost#90570476 as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeSupergroupBoost#90570476: field photo: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeSupergroupBoost) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeSupergroupBoost#90570476 to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeSupergroupBoost#90570476: field photo: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeSupergroupBoost) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeSupergroupBoost#90570476 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeSupergroupBoost")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeSupergroupBoost#90570476: field photo: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeSupergroupBoost) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeSupergroupBoost#90570476 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeSupergroupBoost"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeSupergroupBoost#90570476: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeSupergroupBoost#90570476: field photo: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeSupergroupBoost) GetPhoto() (value ChatPhoto) {
	if l == nil {
		return
	}
	return l.Photo
}

// LinkPreviewTypeTheme represents TL type `linkPreviewTypeTheme#6b7a9ba5`.
type LinkPreviewTypeTheme struct {
	// The list of files with theme description
	Documents []Document
	// Settings for the cloud theme; may be null if unknown
	Settings ThemeSettings
}

// LinkPreviewTypeThemeTypeID is TL type id of LinkPreviewTypeTheme.
const LinkPreviewTypeThemeTypeID = 0x6b7a9ba5

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeTheme) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeTheme{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeTheme) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeTheme",
		ID:   LinkPreviewTypeThemeTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Documents",
			SchemaName: "documents",
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeTheme) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeTheme#6b7a9ba5 as nil")
	}
	b.PutID(LinkPreviewTypeThemeTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeTheme) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeTheme#6b7a9ba5 as nil")
	}
	b.PutInt(len(l.Documents))
	for idx, v := range l.Documents {
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare linkPreviewTypeTheme#6b7a9ba5: field documents element with index %d: %w", idx, err)
		}
	}
	if err := l.Settings.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeTheme#6b7a9ba5: field settings: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeTheme) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeTheme#6b7a9ba5 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeThemeTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeTheme) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeTheme#6b7a9ba5 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: field documents: %w", err)
		}

		if headerLen > 0 {
			l.Documents = make([]Document, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value Document
			if err := value.DecodeBare(b); err != nil {
				return fmt.Errorf("unable to decode bare linkPreviewTypeTheme#6b7a9ba5: field documents: %w", err)
			}
			l.Documents = append(l.Documents, value)
		}
	}
	{
		if err := l.Settings.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: field settings: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeTheme) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeTheme#6b7a9ba5 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeTheme")
	b.Comma()
	b.FieldStart("documents")
	b.ArrStart()
	for idx, v := range l.Documents {
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode linkPreviewTypeTheme#6b7a9ba5: field documents element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.FieldStart("settings")
	if err := l.Settings.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeTheme#6b7a9ba5: field settings: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeTheme) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeTheme#6b7a9ba5 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeTheme"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: %w", err)
			}
		case "documents":
			if err := b.Arr(func(b tdjson.Decoder) error {
				var value Document
				if err := value.DecodeTDLibJSON(b); err != nil {
					return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: field documents: %w", err)
				}
				l.Documents = append(l.Documents, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: field documents: %w", err)
			}
		case "settings":
			if err := l.Settings.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeTheme#6b7a9ba5: field settings: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetDocuments returns value of Documents field.
func (l *LinkPreviewTypeTheme) GetDocuments() (value []Document) {
	if l == nil {
		return
	}
	return l.Documents
}

// GetSettings returns value of Settings field.
func (l *LinkPreviewTypeTheme) GetSettings() (value ThemeSettings) {
	if l == nil {
		return
	}
	return l.Settings
}

// LinkPreviewTypeUnsupported represents TL type `linkPreviewTypeUnsupported#72b92cb9`.
type LinkPreviewTypeUnsupported struct {
}

// LinkPreviewTypeUnsupportedTypeID is TL type id of LinkPreviewTypeUnsupported.
const LinkPreviewTypeUnsupportedTypeID = 0x72b92cb9

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeUnsupported) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeUnsupported{}
)

func (l *LinkPreviewTypeUnsupported) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeUnsupported) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeUnsupported",
		ID:   LinkPreviewTypeUnsupportedTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeUnsupported) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUnsupported#72b92cb9 as nil")
	}
	b.PutID(LinkPreviewTypeUnsupportedTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeUnsupported) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUnsupported#72b92cb9 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeUnsupported) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUnsupported#72b92cb9 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeUnsupportedTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeUnsupported#72b92cb9: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeUnsupported) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUnsupported#72b92cb9 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeUnsupported) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUnsupported#72b92cb9 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeUnsupported")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeUnsupported) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUnsupported#72b92cb9 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeUnsupported"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeUnsupported#72b92cb9: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// LinkPreviewTypeUpgradedGift represents TL type `linkPreviewTypeUpgradedGift#117aa30f`.
type LinkPreviewTypeUpgradedGift struct {
	// The gift
	Gift UpgradedGift
}

// LinkPreviewTypeUpgradedGiftTypeID is TL type id of LinkPreviewTypeUpgradedGift.
const LinkPreviewTypeUpgradedGiftTypeID = 0x117aa30f

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeUpgradedGift) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeUpgradedGift{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeUpgradedGift) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUpgradedGift#117aa30f as nil")
	}
	b.PutID(LinkPreviewTypeUpgradedGiftTypeID)
	return l.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeUpgradedGift) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUpgradedGift#117aa30f to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeUpgradedGiftTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeUpgradedGift#117aa30f: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeUpgradedGift) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUpgradedGift#117aa30f to nil")
	}
	{
		if err := l.Gift.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeUpgradedGift#117aa30f: field gift: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeUpgradedGift) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUpgradedGift#117aa30f as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeUpgradedGift")
	b.Comma()
	b.FieldStart("gift")
	if err := l.Gift.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeUpgradedGift#117aa30f: field gift: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeUpgradedGift) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUpgradedGift#117aa30f to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeUpgradedGift"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeUpgradedGift#117aa30f: %w", err)
			}
		case "gift":
			if err := l.Gift.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeUpgradedGift#117aa30f: field gift: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetGift returns value of Gift field.
func (l *LinkPreviewTypeUpgradedGift) GetGift() (value UpgradedGift) {
	if l == nil {
		return
	}
	return l.Gift
}

// LinkPreviewTypeUser represents TL type `linkPreviewTypeUser#a8ad817c`.
type LinkPreviewTypeUser struct {
	// Photo of the user; may be null if none
	Photo ChatPhoto
	// True, if the user is a bot
	IsBot bool
}

// LinkPreviewTypeUserTypeID is TL type id of LinkPreviewTypeUser.
const LinkPreviewTypeUserTypeID = 0xa8ad817c

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeUser) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeUser{}
)

func (l *LinkPreviewTypeUser) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}
	if !(l.IsBot == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeUser) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeUser",
		ID:   LinkPreviewTypeUserTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
		{
			Name:       "IsBot",
			SchemaName: "is_bot",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeUser) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUser#a8ad817c as nil")
	}
	b.PutID(LinkPreviewTypeUserTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeUser) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUser#a8ad817c as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeUser#a8ad817c: field photo: %w", err)
	}
	b.PutBool(l.IsBot)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeUser) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUser#a8ad817c to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeUser#a8ad817c: field photo: %w", err)
		}
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeUser#a8ad817c: field is_bot: %w", err)
		}
		l.IsBot = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeUser) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeUser#a8ad817c as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeUser")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeUser#a8ad817c: field photo: %w", err)
	}
	b.Comma()
	b.FieldStart("is_bot")
	b.PutBool(l.IsBot)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeUser) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeUser#a8ad817c to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeUser"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeUser#a8ad817c: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeUser#a8ad817c: field photo: %w", err)
			}
		case "is_bot":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeUser#a8ad817c: field is_bot: %w", err)
			}
			l.IsBot = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeUser) GetPhoto() (value ChatPhoto) {
	if l == nil {
		return
	}
	return l.Photo
}

// GetIsBot returns value of IsBot field.
func (l *LinkPreviewTypeUser) GetIsBot() (value bool) {
	if l == nil {
		return
	}
	return l.IsBot
}

// LinkPreviewTypeVideo represents TL type `linkPreviewTypeVideo#5dc2f586`.
type LinkPreviewTypeVideo struct {
	// The video description
	Video Video
	// Cover of the video; may be null if none
	Cover Photo
	// Timestamp from which the video playing must start, in seconds
	StartTimestamp int32
}

// LinkPreviewTypeVideoTypeID is TL type id of LinkPreviewTypeVideo.
const LinkPreviewTypeVideoTypeID = 0x5dc2f586

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeVideo) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeVideo{}
)

func (l *LinkPreviewTypeVideo) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Video.Zero()) {
		return false
	}
	if !(l.Cover.Zero()) {
		return false
	}
	if !(l.StartTimestamp == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeVideo) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeVideo",
		ID:   LinkPreviewTypeVideoTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Video",
			SchemaName: "video",
		},
		{
			Name:       "Cover",
			SchemaName: "cover",
		},
		{
			Name:       "StartTimestamp",
			SchemaName: "start_timestamp",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeVideo) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideo#5dc2f586 as nil")
	}
	b.PutID(LinkPreviewTypeVideoTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeVideo) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideo#5dc2f586 as nil")
	}
	if err := l.Video.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideo#5dc2f586: field video: %w", err)
	}
	if err := l.Cover.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideo#5dc2f586: field cover: %w", err)
	}
	b.PutInt32(l.StartTimestamp)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeVideo) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideo#5dc2f586 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeVideoTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeVideo) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideo#5dc2f586 to nil")
	}
	{
		if err := l.Video.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: field video: %w", err)
		}
	}
	{
		if err := l.Cover.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: field cover: %w", err)
		}
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: field start_timestamp: %w", err)
		}
		l.StartTimestamp = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeVideo) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideo#5dc2f586 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeVideo")
	b.Comma()
	b.FieldStart("video")
	if err := l.Video.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideo#5dc2f586: field video: %w", err)
	}
	b.Comma()
	b.FieldStart("cover")
	if err := l.Cover.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideo#5dc2f586: field cover: %w", err)
	}
	b.Comma()
	b.FieldStart("start_timestamp")
	b.PutInt32(l.StartTimestamp)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeVideo) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideo#5dc2f586 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeVideo"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: %w", err)
			}
		case "video":
			if err := l.Video.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: field video: %w", err)
			}
		case "cover":
			if err := l.Cover.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: field cover: %w", err)
			}
		case "start_timestamp":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideo#5dc2f586: field start_timestamp: %w", err)
			}
			l.StartTimestamp = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetVideo returns value of Video field.
func (l *LinkPreviewTypeVideo) GetVideo() (value Video) {
	if l == nil {
		return
	}
	return l.Video
}

// GetCover returns value of Cover field.
func (l *LinkPreviewTypeVideo) GetCover() (value Photo) {
	if l == nil {
		return
	}
	return l.Cover
}

// GetStartTimestamp returns value of StartTimestamp field.
func (l *LinkPreviewTypeVideo) GetStartTimestamp() (value int32) {
	if l == nil {
		return
	}
	return l.StartTimestamp
}

// LinkPreviewTypeVideoChat represents TL type `linkPreviewTypeVideoChat#1908ee13`.
type LinkPreviewTypeVideoChat struct {
	// Photo of the chat with the video chat; may be null if none
	Photo ChatPhoto
	// True, if the video chat is expected to be a live stream in a channel or a broadcast
	// group
	IsLiveStream bool
}

// LinkPreviewTypeVideoChatTypeID is TL type id of LinkPreviewTypeVideoChat.
const LinkPreviewTypeVideoChatTypeID = 0x1908ee13

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeVideoChat) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeVideoChat{}
)

func (l *LinkPreviewTypeVideoChat) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}
	if !(l.IsLiveStream == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeVideoChat) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeVideoChat",
		ID:   LinkPreviewTypeVideoChatTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
		{
			Name:       "IsLiveStream",
			SchemaName: "is_live_stream",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeVideoChat) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideoChat#1908ee13 as nil")
	}
	b.PutID(LinkPreviewTypeVideoChatTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeVideoChat) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideoChat#1908ee13 as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideoChat#1908ee13: field photo: %w", err)
	}
	b.PutBool(l.IsLiveStream)
	return nil
}

// Decode implements bin.Decoder.
func (l *LinkPreviewTypeVideoChat) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideoChat#1908ee13 to nil")
	}
	if err := b.ConsumeID(LinkPreviewTypeVideoChatTypeID); err != nil {
		return fmt.Errorf("unable to decode linkPreviewTypeVideoChat#1908ee13: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeVideoChat) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideoChat#1908ee13 to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVideoChat#1908ee13: field photo: %w", err)
		}
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVideoChat#1908ee13: field is_live_stream: %w", err)
		}
		l.IsLiveStream = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeVideoChat) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideoChat#1908ee13 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeVideoChat")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideoChat#1908ee13: field photo: %w", err)
	}
	b.Comma()
	b.FieldStart("is_live_stream")
	b.PutBool(l.IsLiveStream)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeVideoChat) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideoChat#1908ee13 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeVideoChat"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideoChat#1908ee13: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideoChat#1908ee13: field photo: %w", err)
			}
		case "is_live_stream":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideoChat#1908ee13: field is_live_stream: %w", err)
			}
			l.IsLiveStream = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeVideoChat) GetPhoto() (value ChatPhoto) {
	if l == nil {
		return
	}
	return l.Photo
}

// GetIsLiveStream returns value of IsLiveStream field.
func (l *LinkPreviewTypeVideoChat) GetIsLiveStream() (value bool) {
	if l == nil {
		return
	}
	return l.IsLiveStream
}

// LinkPreviewTypeVideoNote represents TL type `linkPreviewTypeVideoNote#cf70db61`.
type LinkPreviewTypeVideoNote struct {
	// The video note
	VideoNote VideoNote
}

// LinkPreviewTypeVideoNoteTypeID is TL type id of LinkPreviewTypeVideoNote.
const LinkPreviewTypeVideoNoteTypeID = 0xcf70db61

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeVideoNote) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeVideoNote{}
)

func (l *LinkPreviewTypeVideoNote) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.VideoNote.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeVideoNote) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeVideoNote",
		ID:   LinkPreviewTypeVideoNoteTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "VideoNote",
			SchemaName: "video_note",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeVideoNote) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideoNote#cf70db61 as nil")
	}
	b.PutID(LinkPreviewTypeVideoNoteTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeVideoNote) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideoNote#cf70db61 as nil")
	}
	if err := l.VideoNote.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideoNote#cf70db61: field video_note: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeVideoNote) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideoNote#cf70db61 to nil")
	}
	{
		if err := l.VideoNote.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVideoNote#cf70db61: field video_note: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeVideoNote) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVideoNote#cf70db61 as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeVideoNote")
	b.Comma()
	b.FieldStart("video_note")
	if err := l.VideoNote.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVideoNote#cf70db61: field video_note: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeVideoNote) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVideoNote#cf70db61 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeVideoNote"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideoNote#cf70db61: %w", err)
			}
		case "video_note":
			if err := l.VideoNote.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVideoNote#cf70db61: field video_note: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetVideoNote returns value of VideoNote field.
func (l *LinkPreviewTypeVideoNote) GetVideoNote() (value VideoNote) {
	if l == nil {
		return
	}
	return l.VideoNote
}

// LinkPreviewTypeVoiceNote represents TL type `linkPreviewTypeVoiceNote#d2d2cf2b`.
type LinkPreviewTypeVoiceNote struct {
	// The voice note
	VoiceNote VoiceNote
}

// LinkPreviewTypeVoiceNoteTypeID is TL type id of LinkPreviewTypeVoiceNote.
const LinkPreviewTypeVoiceNoteTypeID = 0xd2d2cf2b

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeVoiceNote) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeVoiceNote{}
)

func (l *LinkPreviewTypeVoiceNote) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.VoiceNote.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeVoiceNote) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeVoiceNote",
		ID:   LinkPreviewTypeVoiceNoteTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "VoiceNote",
			SchemaName: "voice_note",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeVoiceNote) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVoiceNote#d2d2cf2b as nil")
	}
	b.PutID(LinkPreviewTypeVoiceNoteTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeVoiceNote) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVoiceNote#d2d2cf2b as nil")
	}
	if err := l.VoiceNote.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVoiceNote#d2d2cf2b: field voice_note: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeVoiceNote) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVoiceNote#d2d2cf2b to nil")
	}
	{
		if err := l.VoiceNote.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeVoiceNote#d2d2cf2b: field voice_note: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeVoiceNote) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeVoiceNote#d2d2cf2b as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeVoiceNote")
	b.Comma()
	b.FieldStart("voice_note")
	if err := l.VoiceNote.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeVoiceNote#d2d2cf2b: field voice_note: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeVoiceNote) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeVoiceNote#d2d2cf2b to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeVoiceNote"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVoiceNote#d2d2cf2b: %w", err)
			}
		case "voice_note":
			if err := l.VoiceNote.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeVoiceNote#d2d2cf2b: field voice_note: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetVoiceNote returns value of VoiceNote field.
func (l *LinkPreviewTypeVoiceNote) GetVoiceNote() (value VoiceNote) {
	if l == nil {
		return
	}
	return l.VoiceNote
}

// LinkPreviewTypeWebApp represents TL type `linkPreviewTypeWebApp#a62eef8a`.
type LinkPreviewTypeWebApp struct {
	// Web App photo; may be null if none
	Photo Photo
}

// LinkPreviewTypeWebAppTypeID is TL type id of LinkPreviewTypeWebApp.
const LinkPreviewTypeWebAppTypeID = 0xa62eef8a

// construct implements constructor of LinkPreviewTypeClass.
func (l LinkPreviewTypeWebApp) construct() LinkPreviewTypeClass { return &l }

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

	_ LinkPreviewTypeClass = &LinkPreviewTypeWebApp{}
)

func (l *LinkPreviewTypeWebApp) Zero() bool {
	if l == nil {
		return true
	}
	if !(l.Photo.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (l *LinkPreviewTypeWebApp) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "linkPreviewTypeWebApp",
		ID:   LinkPreviewTypeWebAppTypeID,
	}
	if l == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (l *LinkPreviewTypeWebApp) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeWebApp#a62eef8a as nil")
	}
	b.PutID(LinkPreviewTypeWebAppTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LinkPreviewTypeWebApp) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeWebApp#a62eef8a as nil")
	}
	if err := l.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeWebApp#a62eef8a: field photo: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (l *LinkPreviewTypeWebApp) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeWebApp#a62eef8a to nil")
	}
	{
		if err := l.Photo.Decode(b); err != nil {
			return fmt.Errorf("unable to decode linkPreviewTypeWebApp#a62eef8a: field photo: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (l *LinkPreviewTypeWebApp) EncodeTDLibJSON(b tdjson.Encoder) error {
	if l == nil {
		return fmt.Errorf("can't encode linkPreviewTypeWebApp#a62eef8a as nil")
	}
	b.ObjStart()
	b.PutID("linkPreviewTypeWebApp")
	b.Comma()
	b.FieldStart("photo")
	if err := l.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode linkPreviewTypeWebApp#a62eef8a: field photo: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LinkPreviewTypeWebApp) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode linkPreviewTypeWebApp#a62eef8a to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("linkPreviewTypeWebApp"); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeWebApp#a62eef8a: %w", err)
			}
		case "photo":
			if err := l.Photo.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode linkPreviewTypeWebApp#a62eef8a: field photo: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPhoto returns value of Photo field.
func (l *LinkPreviewTypeWebApp) GetPhoto() (value Photo) {
	if l == nil {
		return
	}
	return l.Photo
}

// LinkPreviewTypeClassName is schema name of LinkPreviewTypeClass.
const LinkPreviewTypeClassName = "LinkPreviewType"

// LinkPreviewTypeClass represents LinkPreviewType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeLinkPreviewType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.LinkPreviewTypeAlbum: // linkPreviewTypeAlbum#186d97b4
//	case *tdapi.LinkPreviewTypeAnimation: // linkPreviewTypeAnimation#ad5cc534
//	case *tdapi.LinkPreviewTypeApp: // linkPreviewTypeApp#e3a68def
//	case *tdapi.LinkPreviewTypeArticle: // linkPreviewTypeArticle#7cce9bd9
//	case *tdapi.LinkPreviewTypeAudio: // linkPreviewTypeAudio#75e407d2
//	case *tdapi.LinkPreviewTypeBackground: // linkPreviewTypeBackground#3a48a1e0
//	case *tdapi.LinkPreviewTypeChannelBoost: // linkPreviewTypeChannelBoost#c6f40456
//	case *tdapi.LinkPreviewTypeChat: // linkPreviewTypeChat#ae2fa122
//	case *tdapi.LinkPreviewTypeDocument: // linkPreviewTypeDocument#bf0169a2
//	case *tdapi.LinkPreviewTypeEmbeddedAnimationPlayer: // linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605
//	case *tdapi.LinkPreviewTypeEmbeddedAudioPlayer: // linkPreviewTypeEmbeddedAudioPlayer#220b429c
//	case *tdapi.LinkPreviewTypeEmbeddedVideoPlayer: // linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03
//	case *tdapi.LinkPreviewTypeExternalAudio: // linkPreviewTypeExternalAudio#8a82ffed
//	case *tdapi.LinkPreviewTypeExternalVideo: // linkPreviewTypeExternalVideo#517dcb98
//	case *tdapi.LinkPreviewTypeGroupCall: // linkPreviewTypeGroupCall#b5f190e0
//	case *tdapi.LinkPreviewTypeInvoice: // linkPreviewTypeInvoice#d47f48da
//	case *tdapi.LinkPreviewTypeMessage: // linkPreviewTypeMessage#19f4c19e
//	case *tdapi.LinkPreviewTypePhoto: // linkPreviewTypePhoto#aecfaaac
//	case *tdapi.LinkPreviewTypePremiumGiftCode: // linkPreviewTypePremiumGiftCode#4e0d80b1
//	case *tdapi.LinkPreviewTypeShareableChatFolder: // linkPreviewTypeShareableChatFolder#805ab33c
//	case *tdapi.LinkPreviewTypeSticker: // linkPreviewTypeSticker#245f4d25
//	case *tdapi.LinkPreviewTypeStickerSet: // linkPreviewTypeStickerSet#cb82a523
//	case *tdapi.LinkPreviewTypeStory: // linkPreviewTypeStory#3e5442db
//	case *tdapi.LinkPreviewTypeSupergroupBoost: // linkPreviewTypeSupergroupBoost#90570476
//	case *tdapi.LinkPreviewTypeTheme: // linkPreviewTypeTheme#6b7a9ba5
//	case *tdapi.LinkPreviewTypeUnsupported: // linkPreviewTypeUnsupported#72b92cb9
//	case *tdapi.LinkPreviewTypeUpgradedGift: // linkPreviewTypeUpgradedGift#117aa30f
//	case *tdapi.LinkPreviewTypeUser: // linkPreviewTypeUser#a8ad817c
//	case *tdapi.LinkPreviewTypeVideo: // linkPreviewTypeVideo#5dc2f586
//	case *tdapi.LinkPreviewTypeVideoChat: // linkPreviewTypeVideoChat#1908ee13
//	case *tdapi.LinkPreviewTypeVideoNote: // linkPreviewTypeVideoNote#cf70db61
//	case *tdapi.LinkPreviewTypeVoiceNote: // linkPreviewTypeVoiceNote#d2d2cf2b
//	case *tdapi.LinkPreviewTypeWebApp: // linkPreviewTypeWebApp#a62eef8a
//	default: panic(v)
//	}
type LinkPreviewTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() LinkPreviewTypeClass

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

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeLinkPreviewType implements binary de-serialization for LinkPreviewTypeClass.
func DecodeLinkPreviewType(buf *bin.Buffer) (LinkPreviewTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case LinkPreviewTypeAlbumTypeID:
		// Decoding linkPreviewTypeAlbum#186d97b4.
		v := LinkPreviewTypeAlbum{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeAnimationTypeID:
		// Decoding linkPreviewTypeAnimation#ad5cc534.
		v := LinkPreviewTypeAnimation{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeAppTypeID:
		// Decoding linkPreviewTypeApp#e3a68def.
		v := LinkPreviewTypeApp{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeArticleTypeID:
		// Decoding linkPreviewTypeArticle#7cce9bd9.
		v := LinkPreviewTypeArticle{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeAudioTypeID:
		// Decoding linkPreviewTypeAudio#75e407d2.
		v := LinkPreviewTypeAudio{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeBackgroundTypeID:
		// Decoding linkPreviewTypeBackground#3a48a1e0.
		v := LinkPreviewTypeBackground{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeChannelBoostTypeID:
		// Decoding linkPreviewTypeChannelBoost#c6f40456.
		v := LinkPreviewTypeChannelBoost{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeChatTypeID:
		// Decoding linkPreviewTypeChat#ae2fa122.
		v := LinkPreviewTypeChat{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeDocumentTypeID:
		// Decoding linkPreviewTypeDocument#bf0169a2.
		v := LinkPreviewTypeDocument{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeEmbeddedAnimationPlayerTypeID:
		// Decoding linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605.
		v := LinkPreviewTypeEmbeddedAnimationPlayer{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeEmbeddedAudioPlayerTypeID:
		// Decoding linkPreviewTypeEmbeddedAudioPlayer#220b429c.
		v := LinkPreviewTypeEmbeddedAudioPlayer{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeEmbeddedVideoPlayerTypeID:
		// Decoding linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03.
		v := LinkPreviewTypeEmbeddedVideoPlayer{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeExternalAudioTypeID:
		// Decoding linkPreviewTypeExternalAudio#8a82ffed.
		v := LinkPreviewTypeExternalAudio{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeExternalVideoTypeID:
		// Decoding linkPreviewTypeExternalVideo#517dcb98.
		v := LinkPreviewTypeExternalVideo{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeGroupCallTypeID:
		// Decoding linkPreviewTypeGroupCall#b5f190e0.
		v := LinkPreviewTypeGroupCall{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeInvoiceTypeID:
		// Decoding linkPreviewTypeInvoice#d47f48da.
		v := LinkPreviewTypeInvoice{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeMessageTypeID:
		// Decoding linkPreviewTypeMessage#19f4c19e.
		v := LinkPreviewTypeMessage{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypePhotoTypeID:
		// Decoding linkPreviewTypePhoto#aecfaaac.
		v := LinkPreviewTypePhoto{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypePremiumGiftCodeTypeID:
		// Decoding linkPreviewTypePremiumGiftCode#4e0d80b1.
		v := LinkPreviewTypePremiumGiftCode{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeShareableChatFolderTypeID:
		// Decoding linkPreviewTypeShareableChatFolder#805ab33c.
		v := LinkPreviewTypeShareableChatFolder{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeStickerTypeID:
		// Decoding linkPreviewTypeSticker#245f4d25.
		v := LinkPreviewTypeSticker{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeStickerSetTypeID:
		// Decoding linkPreviewTypeStickerSet#cb82a523.
		v := LinkPreviewTypeStickerSet{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeStoryTypeID:
		// Decoding linkPreviewTypeStory#3e5442db.
		v := LinkPreviewTypeStory{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeSupergroupBoostTypeID:
		// Decoding linkPreviewTypeSupergroupBoost#90570476.
		v := LinkPreviewTypeSupergroupBoost{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeThemeTypeID:
		// Decoding linkPreviewTypeTheme#6b7a9ba5.
		v := LinkPreviewTypeTheme{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeUnsupportedTypeID:
		// Decoding linkPreviewTypeUnsupported#72b92cb9.
		v := LinkPreviewTypeUnsupported{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeUpgradedGiftTypeID:
		// Decoding linkPreviewTypeUpgradedGift#117aa30f.
		v := LinkPreviewTypeUpgradedGift{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeUserTypeID:
		// Decoding linkPreviewTypeUser#a8ad817c.
		v := LinkPreviewTypeUser{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeVideoTypeID:
		// Decoding linkPreviewTypeVideo#5dc2f586.
		v := LinkPreviewTypeVideo{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeVideoChatTypeID:
		// Decoding linkPreviewTypeVideoChat#1908ee13.
		v := LinkPreviewTypeVideoChat{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeVideoNoteTypeID:
		// Decoding linkPreviewTypeVideoNote#cf70db61.
		v := LinkPreviewTypeVideoNote{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeVoiceNoteTypeID:
		// Decoding linkPreviewTypeVoiceNote#d2d2cf2b.
		v := LinkPreviewTypeVoiceNote{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case LinkPreviewTypeWebAppTypeID:
		// Decoding linkPreviewTypeWebApp#a62eef8a.
		v := LinkPreviewTypeWebApp{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONLinkPreviewType implements binary de-serialization for LinkPreviewTypeClass.
func DecodeTDLibJSONLinkPreviewType(buf tdjson.Decoder) (LinkPreviewTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "linkPreviewTypeAlbum":
		// Decoding linkPreviewTypeAlbum#186d97b4.
		v := LinkPreviewTypeAlbum{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeAnimation":
		// Decoding linkPreviewTypeAnimation#ad5cc534.
		v := LinkPreviewTypeAnimation{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeApp":
		// Decoding linkPreviewTypeApp#e3a68def.
		v := LinkPreviewTypeApp{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeArticle":
		// Decoding linkPreviewTypeArticle#7cce9bd9.
		v := LinkPreviewTypeArticle{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeAudio":
		// Decoding linkPreviewTypeAudio#75e407d2.
		v := LinkPreviewTypeAudio{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeBackground":
		// Decoding linkPreviewTypeBackground#3a48a1e0.
		v := LinkPreviewTypeBackground{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeChannelBoost":
		// Decoding linkPreviewTypeChannelBoost#c6f40456.
		v := LinkPreviewTypeChannelBoost{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeChat":
		// Decoding linkPreviewTypeChat#ae2fa122.
		v := LinkPreviewTypeChat{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeDocument":
		// Decoding linkPreviewTypeDocument#bf0169a2.
		v := LinkPreviewTypeDocument{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeEmbeddedAnimationPlayer":
		// Decoding linkPreviewTypeEmbeddedAnimationPlayer#aa5ad605.
		v := LinkPreviewTypeEmbeddedAnimationPlayer{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeEmbeddedAudioPlayer":
		// Decoding linkPreviewTypeEmbeddedAudioPlayer#220b429c.
		v := LinkPreviewTypeEmbeddedAudioPlayer{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeEmbeddedVideoPlayer":
		// Decoding linkPreviewTypeEmbeddedVideoPlayer#a7bfbb03.
		v := LinkPreviewTypeEmbeddedVideoPlayer{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeExternalAudio":
		// Decoding linkPreviewTypeExternalAudio#8a82ffed.
		v := LinkPreviewTypeExternalAudio{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeExternalVideo":
		// Decoding linkPreviewTypeExternalVideo#517dcb98.
		v := LinkPreviewTypeExternalVideo{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeGroupCall":
		// Decoding linkPreviewTypeGroupCall#b5f190e0.
		v := LinkPreviewTypeGroupCall{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeInvoice":
		// Decoding linkPreviewTypeInvoice#d47f48da.
		v := LinkPreviewTypeInvoice{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeMessage":
		// Decoding linkPreviewTypeMessage#19f4c19e.
		v := LinkPreviewTypeMessage{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypePhoto":
		// Decoding linkPreviewTypePhoto#aecfaaac.
		v := LinkPreviewTypePhoto{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypePremiumGiftCode":
		// Decoding linkPreviewTypePremiumGiftCode#4e0d80b1.
		v := LinkPreviewTypePremiumGiftCode{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeShareableChatFolder":
		// Decoding linkPreviewTypeShareableChatFolder#805ab33c.
		v := LinkPreviewTypeShareableChatFolder{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeSticker":
		// Decoding linkPreviewTypeSticker#245f4d25.
		v := LinkPreviewTypeSticker{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeStickerSet":
		// Decoding linkPreviewTypeStickerSet#cb82a523.
		v := LinkPreviewTypeStickerSet{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeStory":
		// Decoding linkPreviewTypeStory#3e5442db.
		v := LinkPreviewTypeStory{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeSupergroupBoost":
		// Decoding linkPreviewTypeSupergroupBoost#90570476.
		v := LinkPreviewTypeSupergroupBoost{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeTheme":
		// Decoding linkPreviewTypeTheme#6b7a9ba5.
		v := LinkPreviewTypeTheme{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeUnsupported":
		// Decoding linkPreviewTypeUnsupported#72b92cb9.
		v := LinkPreviewTypeUnsupported{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeUpgradedGift":
		// Decoding linkPreviewTypeUpgradedGift#117aa30f.
		v := LinkPreviewTypeUpgradedGift{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeUser":
		// Decoding linkPreviewTypeUser#a8ad817c.
		v := LinkPreviewTypeUser{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeVideo":
		// Decoding linkPreviewTypeVideo#5dc2f586.
		v := LinkPreviewTypeVideo{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeVideoChat":
		// Decoding linkPreviewTypeVideoChat#1908ee13.
		v := LinkPreviewTypeVideoChat{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeVideoNote":
		// Decoding linkPreviewTypeVideoNote#cf70db61.
		v := LinkPreviewTypeVideoNote{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeVoiceNote":
		// Decoding linkPreviewTypeVoiceNote#d2d2cf2b.
		v := LinkPreviewTypeVoiceNote{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	case "linkPreviewTypeWebApp":
		// Decoding linkPreviewTypeWebApp#a62eef8a.
		v := LinkPreviewTypeWebApp{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode LinkPreviewTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// LinkPreviewType boxes the LinkPreviewTypeClass providing a helper.
type LinkPreviewTypeBox struct {
	LinkPreviewType LinkPreviewTypeClass
}

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

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

// DecodeTDLibJSON implements bin.Decoder for LinkPreviewTypeBox.
func (b *LinkPreviewTypeBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode LinkPreviewTypeBox to nil")
	}
	v, err := DecodeTDLibJSONLinkPreviewType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.LinkPreviewType = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for LinkPreviewTypeBox.
func (b *LinkPreviewTypeBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.LinkPreviewType == nil {
		return fmt.Errorf("unable to encode LinkPreviewTypeClass as nil")
	}
	return b.LinkPreviewType.EncodeTDLibJSON(buf)
}
