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

// TMeURLTypeUser represents TL type `tMeUrlTypeUser#7787c1a`.
type TMeURLTypeUser struct {
	// Identifier of the user
	UserID int64
}

// TMeURLTypeUserTypeID is TL type id of TMeURLTypeUser.
const TMeURLTypeUserTypeID = 0x7787c1a

// construct implements constructor of TMeURLTypeClass.
func (t TMeURLTypeUser) construct() TMeURLTypeClass { return &t }

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

	_ TMeURLTypeClass = &TMeURLTypeUser{}
)

func (t *TMeURLTypeUser) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.UserID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TMeURLTypeUser) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "tMeUrlTypeUser",
		ID:   TMeURLTypeUserTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TMeURLTypeUser) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeUser#7787c1a as nil")
	}
	b.PutID(TMeURLTypeUserTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TMeURLTypeUser) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeUser#7787c1a as nil")
	}
	b.PutInt53(t.UserID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *TMeURLTypeUser) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode tMeUrlTypeUser#7787c1a to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode tMeUrlTypeUser#7787c1a: field user_id: %w", err)
		}
		t.UserID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TMeURLTypeUser) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeUser#7787c1a as nil")
	}
	b.ObjStart()
	b.PutID("tMeUrlTypeUser")
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(t.UserID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TMeURLTypeUser) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode tMeUrlTypeUser#7787c1a to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("tMeUrlTypeUser"); err != nil {
				return fmt.Errorf("unable to decode tMeUrlTypeUser#7787c1a: %w", err)
			}
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode tMeUrlTypeUser#7787c1a: field user_id: %w", err)
			}
			t.UserID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserID returns value of UserID field.
func (t *TMeURLTypeUser) GetUserID() (value int64) {
	if t == nil {
		return
	}
	return t.UserID
}

// TMeURLTypeSupergroup represents TL type `tMeUrlTypeSupergroup#af5536a8`.
type TMeURLTypeSupergroup struct {
	// Identifier of the supergroup or channel
	SupergroupID int64
}

// TMeURLTypeSupergroupTypeID is TL type id of TMeURLTypeSupergroup.
const TMeURLTypeSupergroupTypeID = 0xaf5536a8

// construct implements constructor of TMeURLTypeClass.
func (t TMeURLTypeSupergroup) construct() TMeURLTypeClass { return &t }

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

	_ TMeURLTypeClass = &TMeURLTypeSupergroup{}
)

func (t *TMeURLTypeSupergroup) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.SupergroupID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TMeURLTypeSupergroup) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "tMeUrlTypeSupergroup",
		ID:   TMeURLTypeSupergroupTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SupergroupID",
			SchemaName: "supergroup_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TMeURLTypeSupergroup) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeSupergroup#af5536a8 as nil")
	}
	b.PutID(TMeURLTypeSupergroupTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TMeURLTypeSupergroup) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeSupergroup#af5536a8 as nil")
	}
	b.PutInt53(t.SupergroupID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *TMeURLTypeSupergroup) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode tMeUrlTypeSupergroup#af5536a8 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode tMeUrlTypeSupergroup#af5536a8: field supergroup_id: %w", err)
		}
		t.SupergroupID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TMeURLTypeSupergroup) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeSupergroup#af5536a8 as nil")
	}
	b.ObjStart()
	b.PutID("tMeUrlTypeSupergroup")
	b.Comma()
	b.FieldStart("supergroup_id")
	b.PutInt53(t.SupergroupID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetSupergroupID returns value of SupergroupID field.
func (t *TMeURLTypeSupergroup) GetSupergroupID() (value int64) {
	if t == nil {
		return
	}
	return t.SupergroupID
}

// TMeURLTypeChatInvite represents TL type `tMeUrlTypeChatInvite#12b5da49`.
type TMeURLTypeChatInvite struct {
	// Information about the chat invite link
	Info ChatInviteLinkInfo
}

// TMeURLTypeChatInviteTypeID is TL type id of TMeURLTypeChatInvite.
const TMeURLTypeChatInviteTypeID = 0x12b5da49

// construct implements constructor of TMeURLTypeClass.
func (t TMeURLTypeChatInvite) construct() TMeURLTypeClass { return &t }

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

	_ TMeURLTypeClass = &TMeURLTypeChatInvite{}
)

func (t *TMeURLTypeChatInvite) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.Info.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TMeURLTypeChatInvite) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "tMeUrlTypeChatInvite",
		ID:   TMeURLTypeChatInviteTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Info",
			SchemaName: "info",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TMeURLTypeChatInvite) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeChatInvite#12b5da49 as nil")
	}
	b.PutID(TMeURLTypeChatInviteTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TMeURLTypeChatInvite) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeChatInvite#12b5da49 as nil")
	}
	if err := t.Info.Encode(b); err != nil {
		return fmt.Errorf("unable to encode tMeUrlTypeChatInvite#12b5da49: field info: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *TMeURLTypeChatInvite) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode tMeUrlTypeChatInvite#12b5da49 to nil")
	}
	{
		if err := t.Info.Decode(b); err != nil {
			return fmt.Errorf("unable to decode tMeUrlTypeChatInvite#12b5da49: field info: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TMeURLTypeChatInvite) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeChatInvite#12b5da49 as nil")
	}
	b.ObjStart()
	b.PutID("tMeUrlTypeChatInvite")
	b.Comma()
	b.FieldStart("info")
	if err := t.Info.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode tMeUrlTypeChatInvite#12b5da49: field info: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TMeURLTypeChatInvite) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode tMeUrlTypeChatInvite#12b5da49 to nil")
	}

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

// GetInfo returns value of Info field.
func (t *TMeURLTypeChatInvite) GetInfo() (value ChatInviteLinkInfo) {
	if t == nil {
		return
	}
	return t.Info
}

// TMeURLTypeStickerSet represents TL type `tMeUrlTypeStickerSet#5f83ccec`.
type TMeURLTypeStickerSet struct {
	// Identifier of the sticker set
	StickerSetID int64
}

// TMeURLTypeStickerSetTypeID is TL type id of TMeURLTypeStickerSet.
const TMeURLTypeStickerSetTypeID = 0x5f83ccec

// construct implements constructor of TMeURLTypeClass.
func (t TMeURLTypeStickerSet) construct() TMeURLTypeClass { return &t }

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

	_ TMeURLTypeClass = &TMeURLTypeStickerSet{}
)

func (t *TMeURLTypeStickerSet) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.StickerSetID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TMeURLTypeStickerSet) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "tMeUrlTypeStickerSet",
		ID:   TMeURLTypeStickerSetTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "StickerSetID",
			SchemaName: "sticker_set_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TMeURLTypeStickerSet) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeStickerSet#5f83ccec as nil")
	}
	b.PutID(TMeURLTypeStickerSetTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TMeURLTypeStickerSet) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeStickerSet#5f83ccec as nil")
	}
	b.PutLong(t.StickerSetID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *TMeURLTypeStickerSet) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode tMeUrlTypeStickerSet#5f83ccec to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode tMeUrlTypeStickerSet#5f83ccec: field sticker_set_id: %w", err)
		}
		t.StickerSetID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TMeURLTypeStickerSet) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode tMeUrlTypeStickerSet#5f83ccec as nil")
	}
	b.ObjStart()
	b.PutID("tMeUrlTypeStickerSet")
	b.Comma()
	b.FieldStart("sticker_set_id")
	b.PutLong(t.StickerSetID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("tMeUrlTypeStickerSet"); err != nil {
				return fmt.Errorf("unable to decode tMeUrlTypeStickerSet#5f83ccec: %w", err)
			}
		case "sticker_set_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode tMeUrlTypeStickerSet#5f83ccec: field sticker_set_id: %w", err)
			}
			t.StickerSetID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetStickerSetID returns value of StickerSetID field.
func (t *TMeURLTypeStickerSet) GetStickerSetID() (value int64) {
	if t == nil {
		return
	}
	return t.StickerSetID
}

// TMeURLTypeClassName is schema name of TMeURLTypeClass.
const TMeURLTypeClassName = "TMeUrlType"

// TMeURLTypeClass represents TMeUrlType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeTMeURLType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.TMeURLTypeUser: // tMeUrlTypeUser#7787c1a
//	case *tdapi.TMeURLTypeSupergroup: // tMeUrlTypeSupergroup#af5536a8
//	case *tdapi.TMeURLTypeChatInvite: // tMeUrlTypeChatInvite#12b5da49
//	case *tdapi.TMeURLTypeStickerSet: // tMeUrlTypeStickerSet#5f83ccec
//	default: panic(v)
//	}
type TMeURLTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() TMeURLTypeClass

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

// DecodeTMeURLType implements binary de-serialization for TMeURLTypeClass.
func DecodeTMeURLType(buf *bin.Buffer) (TMeURLTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case TMeURLTypeUserTypeID:
		// Decoding tMeUrlTypeUser#7787c1a.
		v := TMeURLTypeUser{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	case TMeURLTypeSupergroupTypeID:
		// Decoding tMeUrlTypeSupergroup#af5536a8.
		v := TMeURLTypeSupergroup{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	case TMeURLTypeChatInviteTypeID:
		// Decoding tMeUrlTypeChatInvite#12b5da49.
		v := TMeURLTypeChatInvite{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	case TMeURLTypeStickerSetTypeID:
		// Decoding tMeUrlTypeStickerSet#5f83ccec.
		v := TMeURLTypeStickerSet{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONTMeURLType implements binary de-serialization for TMeURLTypeClass.
func DecodeTDLibJSONTMeURLType(buf tdjson.Decoder) (TMeURLTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "tMeUrlTypeUser":
		// Decoding tMeUrlTypeUser#7787c1a.
		v := TMeURLTypeUser{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	case "tMeUrlTypeSupergroup":
		// Decoding tMeUrlTypeSupergroup#af5536a8.
		v := TMeURLTypeSupergroup{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	case "tMeUrlTypeChatInvite":
		// Decoding tMeUrlTypeChatInvite#12b5da49.
		v := TMeURLTypeChatInvite{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	case "tMeUrlTypeStickerSet":
		// Decoding tMeUrlTypeStickerSet#5f83ccec.
		v := TMeURLTypeStickerSet{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode TMeURLTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// TMeURLType boxes the TMeURLTypeClass providing a helper.
type TMeURLTypeBox struct {
	TMeUrlType TMeURLTypeClass
}

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

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

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

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