// Code generated by gotdgen, DO NOT EDIT.

package tg

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

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// MessageMediaEmpty represents TL type `messageMediaEmpty#3ded6320`.
// Empty constructor.
//
// See https://core.telegram.org/constructor/messageMediaEmpty for reference.
type MessageMediaEmpty struct {
}

// MessageMediaEmptyTypeID is TL type id of MessageMediaEmpty.
const MessageMediaEmptyTypeID = 0x3ded6320

// construct implements constructor of MessageMediaClass.
func (m MessageMediaEmpty) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaEmpty{}
)

func (m *MessageMediaEmpty) Zero() bool {
	if m == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (m *MessageMediaEmpty) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaEmpty#3ded6320 as nil")
	}
	b.PutID(MessageMediaEmptyTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaEmpty) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaEmpty#3ded6320 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaEmpty) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaEmpty#3ded6320 to nil")
	}
	if err := b.ConsumeID(MessageMediaEmptyTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaEmpty#3ded6320: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaEmpty) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaEmpty#3ded6320 to nil")
	}
	return nil
}

// MessageMediaPhoto represents TL type `messageMediaPhoto#695150d7`.
// Attached photo.
//
// See https://core.telegram.org/constructor/messageMediaPhoto for reference.
type MessageMediaPhoto struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this media should be hidden behind a spoiler warning
	Spoiler bool
	// Photo
	//
	// Use SetPhoto and GetPhoto helpers.
	Photo PhotoClass
	// Time to live in seconds of self-destructing photo
	//
	// Use SetTTLSeconds and GetTTLSeconds helpers.
	TTLSeconds int
}

// MessageMediaPhotoTypeID is TL type id of MessageMediaPhoto.
const MessageMediaPhotoTypeID = 0x695150d7

// construct implements constructor of MessageMediaClass.
func (m MessageMediaPhoto) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaPhoto{}
)

func (m *MessageMediaPhoto) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Flags.Zero()) {
		return false
	}
	if !(m.Spoiler == false) {
		return false
	}
	if !(m.Photo == nil) {
		return false
	}
	if !(m.TTLSeconds == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaPhoto from given interface.
func (m *MessageMediaPhoto) FillFrom(from interface {
	GetSpoiler() (value bool)
	GetPhoto() (value PhotoClass, ok bool)
	GetTTLSeconds() (value int, ok bool)
}) {
	m.Spoiler = from.GetSpoiler()
	if val, ok := from.GetPhoto(); ok {
		m.Photo = val
	}

	if val, ok := from.GetTTLSeconds(); ok {
		m.TTLSeconds = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaPhoto) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaPhoto",
		ID:   MessageMediaPhotoTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Spoiler",
			SchemaName: "spoiler",
			Null:       !m.Flags.Has(3),
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
			Null:       !m.Flags.Has(0),
		},
		{
			Name:       "TTLSeconds",
			SchemaName: "ttl_seconds",
			Null:       !m.Flags.Has(2),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (m *MessageMediaPhoto) SetFlags() {
	if !(m.Spoiler == false) {
		m.Flags.Set(3)
	}
	if !(m.Photo == nil) {
		m.Flags.Set(0)
	}
	if !(m.TTLSeconds == 0) {
		m.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func (m *MessageMediaPhoto) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaPhoto#695150d7 as nil")
	}
	b.PutID(MessageMediaPhotoTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaPhoto) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaPhoto#695150d7 as nil")
	}
	m.SetFlags()
	if err := m.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaPhoto#695150d7: field flags: %w", err)
	}
	if m.Flags.Has(0) {
		if m.Photo == nil {
			return fmt.Errorf("unable to encode messageMediaPhoto#695150d7: field photo is nil")
		}
		if err := m.Photo.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messageMediaPhoto#695150d7: field photo: %w", err)
		}
	}
	if m.Flags.Has(2) {
		b.PutInt(m.TTLSeconds)
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaPhoto) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaPhoto#695150d7 to nil")
	}
	if err := b.ConsumeID(MessageMediaPhotoTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaPhoto#695150d7: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaPhoto) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaPhoto#695150d7 to nil")
	}
	{
		if err := m.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaPhoto#695150d7: field flags: %w", err)
		}
	}
	m.Spoiler = m.Flags.Has(3)
	if m.Flags.Has(0) {
		value, err := DecodePhoto(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaPhoto#695150d7: field photo: %w", err)
		}
		m.Photo = value
	}
	if m.Flags.Has(2) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaPhoto#695150d7: field ttl_seconds: %w", err)
		}
		m.TTLSeconds = value
	}
	return nil
}

// SetSpoiler sets value of Spoiler conditional field.
func (m *MessageMediaPhoto) SetSpoiler(value bool) {
	if value {
		m.Flags.Set(3)
		m.Spoiler = true
	} else {
		m.Flags.Unset(3)
		m.Spoiler = false
	}
}

// GetSpoiler returns value of Spoiler conditional field.
func (m *MessageMediaPhoto) GetSpoiler() (value bool) {
	if m == nil {
		return
	}
	return m.Flags.Has(3)
}

// SetPhoto sets value of Photo conditional field.
func (m *MessageMediaPhoto) SetPhoto(value PhotoClass) {
	m.Flags.Set(0)
	m.Photo = value
}

// GetPhoto returns value of Photo conditional field and
// boolean which is true if field was set.
func (m *MessageMediaPhoto) GetPhoto() (value PhotoClass, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(0) {
		return value, false
	}
	return m.Photo, true
}

// SetTTLSeconds sets value of TTLSeconds conditional field.
func (m *MessageMediaPhoto) SetTTLSeconds(value int) {
	m.Flags.Set(2)
	m.TTLSeconds = value
}

// GetTTLSeconds returns value of TTLSeconds conditional field and
// boolean which is true if field was set.
func (m *MessageMediaPhoto) GetTTLSeconds() (value int, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(2) {
		return value, false
	}
	return m.TTLSeconds, true
}

// MessageMediaGeo represents TL type `messageMediaGeo#56e0d474`.
// Attached map.
//
// See https://core.telegram.org/constructor/messageMediaGeo for reference.
type MessageMediaGeo struct {
	// GeoPoint
	Geo GeoPointClass
}

// MessageMediaGeoTypeID is TL type id of MessageMediaGeo.
const MessageMediaGeoTypeID = 0x56e0d474

// construct implements constructor of MessageMediaClass.
func (m MessageMediaGeo) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaGeo{}
)

func (m *MessageMediaGeo) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Geo == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaGeo from given interface.
func (m *MessageMediaGeo) FillFrom(from interface {
	GetGeo() (value GeoPointClass)
}) {
	m.Geo = from.GetGeo()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaGeo) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaGeo",
		ID:   MessageMediaGeoTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Geo",
			SchemaName: "geo",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaGeo) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaGeo#56e0d474 as nil")
	}
	b.PutID(MessageMediaGeoTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaGeo) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaGeo#56e0d474 as nil")
	}
	if m.Geo == nil {
		return fmt.Errorf("unable to encode messageMediaGeo#56e0d474: field geo is nil")
	}
	if err := m.Geo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaGeo#56e0d474: field geo: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaGeo) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaGeo#56e0d474 to nil")
	}
	if err := b.ConsumeID(MessageMediaGeoTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaGeo#56e0d474: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaGeo) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaGeo#56e0d474 to nil")
	}
	{
		value, err := DecodeGeoPoint(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaGeo#56e0d474: field geo: %w", err)
		}
		m.Geo = value
	}
	return nil
}

// GetGeo returns value of Geo field.
func (m *MessageMediaGeo) GetGeo() (value GeoPointClass) {
	if m == nil {
		return
	}
	return m.Geo
}

// MessageMediaContact represents TL type `messageMediaContact#70322949`.
// Attached contact.
//
// See https://core.telegram.org/constructor/messageMediaContact for reference.
type MessageMediaContact struct {
	// Phone number
	PhoneNumber string
	// Contact's first name
	FirstName string
	// Contact's last name
	LastName string
	// VCARD of contact
	Vcard string
	// User identifier or 0, if the user with the given phone number is not registered
	UserID int64
}

// MessageMediaContactTypeID is TL type id of MessageMediaContact.
const MessageMediaContactTypeID = 0x70322949

// construct implements constructor of MessageMediaClass.
func (m MessageMediaContact) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaContact{}
)

func (m *MessageMediaContact) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.PhoneNumber == "") {
		return false
	}
	if !(m.FirstName == "") {
		return false
	}
	if !(m.LastName == "") {
		return false
	}
	if !(m.Vcard == "") {
		return false
	}
	if !(m.UserID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaContact from given interface.
func (m *MessageMediaContact) FillFrom(from interface {
	GetPhoneNumber() (value string)
	GetFirstName() (value string)
	GetLastName() (value string)
	GetVcard() (value string)
	GetUserID() (value int64)
}) {
	m.PhoneNumber = from.GetPhoneNumber()
	m.FirstName = from.GetFirstName()
	m.LastName = from.GetLastName()
	m.Vcard = from.GetVcard()
	m.UserID = from.GetUserID()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaContact) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaContact",
		ID:   MessageMediaContactTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "PhoneNumber",
			SchemaName: "phone_number",
		},
		{
			Name:       "FirstName",
			SchemaName: "first_name",
		},
		{
			Name:       "LastName",
			SchemaName: "last_name",
		},
		{
			Name:       "Vcard",
			SchemaName: "vcard",
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaContact) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaContact#70322949 as nil")
	}
	b.PutID(MessageMediaContactTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaContact) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaContact#70322949 as nil")
	}
	b.PutString(m.PhoneNumber)
	b.PutString(m.FirstName)
	b.PutString(m.LastName)
	b.PutString(m.Vcard)
	b.PutLong(m.UserID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaContact) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaContact#70322949 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaContact#70322949: field phone_number: %w", err)
		}
		m.PhoneNumber = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaContact#70322949: field first_name: %w", err)
		}
		m.FirstName = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaContact#70322949: field last_name: %w", err)
		}
		m.LastName = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaContact#70322949: field vcard: %w", err)
		}
		m.Vcard = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaContact#70322949: field user_id: %w", err)
		}
		m.UserID = value
	}
	return nil
}

// GetPhoneNumber returns value of PhoneNumber field.
func (m *MessageMediaContact) GetPhoneNumber() (value string) {
	if m == nil {
		return
	}
	return m.PhoneNumber
}

// GetFirstName returns value of FirstName field.
func (m *MessageMediaContact) GetFirstName() (value string) {
	if m == nil {
		return
	}
	return m.FirstName
}

// GetLastName returns value of LastName field.
func (m *MessageMediaContact) GetLastName() (value string) {
	if m == nil {
		return
	}
	return m.LastName
}

// GetVcard returns value of Vcard field.
func (m *MessageMediaContact) GetVcard() (value string) {
	if m == nil {
		return
	}
	return m.Vcard
}

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

// MessageMediaUnsupported represents TL type `messageMediaUnsupported#9f84f49e`.
// Current version of the client does not support this media type.
//
// See https://core.telegram.org/constructor/messageMediaUnsupported for reference.
type MessageMediaUnsupported struct {
}

// MessageMediaUnsupportedTypeID is TL type id of MessageMediaUnsupported.
const MessageMediaUnsupportedTypeID = 0x9f84f49e

// construct implements constructor of MessageMediaClass.
func (m MessageMediaUnsupported) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaUnsupported{}
)

func (m *MessageMediaUnsupported) Zero() bool {
	if m == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (m *MessageMediaUnsupported) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaUnsupported#9f84f49e as nil")
	}
	b.PutID(MessageMediaUnsupportedTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaUnsupported) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaUnsupported#9f84f49e as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaUnsupported) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaUnsupported#9f84f49e to nil")
	}
	if err := b.ConsumeID(MessageMediaUnsupportedTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaUnsupported#9f84f49e: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaUnsupported) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaUnsupported#9f84f49e to nil")
	}
	return nil
}

// MessageMediaDocument represents TL type `messageMediaDocument#9cb070d7`.
// Document (video, audio, voice, sticker, any media type except photo)
//
// See https://core.telegram.org/constructor/messageMediaDocument for reference.
type MessageMediaDocument struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this is a normal sticker, if not set this is a premium sticker and a premium
	// sticker animation must be played.
	Nopremium bool
	// Whether this media should be hidden behind a spoiler warning
	Spoiler bool
	// Attached document
	//
	// Use SetDocument and GetDocument helpers.
	Document DocumentClass
	// Time to live of self-destructing document
	//
	// Use SetTTLSeconds and GetTTLSeconds helpers.
	TTLSeconds int
}

// MessageMediaDocumentTypeID is TL type id of MessageMediaDocument.
const MessageMediaDocumentTypeID = 0x9cb070d7

// construct implements constructor of MessageMediaClass.
func (m MessageMediaDocument) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaDocument{}
)

func (m *MessageMediaDocument) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Flags.Zero()) {
		return false
	}
	if !(m.Nopremium == false) {
		return false
	}
	if !(m.Spoiler == false) {
		return false
	}
	if !(m.Document == nil) {
		return false
	}
	if !(m.TTLSeconds == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaDocument from given interface.
func (m *MessageMediaDocument) FillFrom(from interface {
	GetNopremium() (value bool)
	GetSpoiler() (value bool)
	GetDocument() (value DocumentClass, ok bool)
	GetTTLSeconds() (value int, ok bool)
}) {
	m.Nopremium = from.GetNopremium()
	m.Spoiler = from.GetSpoiler()
	if val, ok := from.GetDocument(); ok {
		m.Document = val
	}

	if val, ok := from.GetTTLSeconds(); ok {
		m.TTLSeconds = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaDocument) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaDocument",
		ID:   MessageMediaDocumentTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Nopremium",
			SchemaName: "nopremium",
			Null:       !m.Flags.Has(3),
		},
		{
			Name:       "Spoiler",
			SchemaName: "spoiler",
			Null:       !m.Flags.Has(4),
		},
		{
			Name:       "Document",
			SchemaName: "document",
			Null:       !m.Flags.Has(0),
		},
		{
			Name:       "TTLSeconds",
			SchemaName: "ttl_seconds",
			Null:       !m.Flags.Has(2),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (m *MessageMediaDocument) SetFlags() {
	if !(m.Nopremium == false) {
		m.Flags.Set(3)
	}
	if !(m.Spoiler == false) {
		m.Flags.Set(4)
	}
	if !(m.Document == nil) {
		m.Flags.Set(0)
	}
	if !(m.TTLSeconds == 0) {
		m.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func (m *MessageMediaDocument) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaDocument#9cb070d7 as nil")
	}
	b.PutID(MessageMediaDocumentTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaDocument) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaDocument#9cb070d7 as nil")
	}
	m.SetFlags()
	if err := m.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaDocument#9cb070d7: field flags: %w", err)
	}
	if m.Flags.Has(0) {
		if m.Document == nil {
			return fmt.Errorf("unable to encode messageMediaDocument#9cb070d7: field document is nil")
		}
		if err := m.Document.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messageMediaDocument#9cb070d7: field document: %w", err)
		}
	}
	if m.Flags.Has(2) {
		b.PutInt(m.TTLSeconds)
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaDocument) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaDocument#9cb070d7 to nil")
	}
	if err := b.ConsumeID(MessageMediaDocumentTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaDocument#9cb070d7: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaDocument) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaDocument#9cb070d7 to nil")
	}
	{
		if err := m.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaDocument#9cb070d7: field flags: %w", err)
		}
	}
	m.Nopremium = m.Flags.Has(3)
	m.Spoiler = m.Flags.Has(4)
	if m.Flags.Has(0) {
		value, err := DecodeDocument(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaDocument#9cb070d7: field document: %w", err)
		}
		m.Document = value
	}
	if m.Flags.Has(2) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaDocument#9cb070d7: field ttl_seconds: %w", err)
		}
		m.TTLSeconds = value
	}
	return nil
}

// SetNopremium sets value of Nopremium conditional field.
func (m *MessageMediaDocument) SetNopremium(value bool) {
	if value {
		m.Flags.Set(3)
		m.Nopremium = true
	} else {
		m.Flags.Unset(3)
		m.Nopremium = false
	}
}

// GetNopremium returns value of Nopremium conditional field.
func (m *MessageMediaDocument) GetNopremium() (value bool) {
	if m == nil {
		return
	}
	return m.Flags.Has(3)
}

// SetSpoiler sets value of Spoiler conditional field.
func (m *MessageMediaDocument) SetSpoiler(value bool) {
	if value {
		m.Flags.Set(4)
		m.Spoiler = true
	} else {
		m.Flags.Unset(4)
		m.Spoiler = false
	}
}

// GetSpoiler returns value of Spoiler conditional field.
func (m *MessageMediaDocument) GetSpoiler() (value bool) {
	if m == nil {
		return
	}
	return m.Flags.Has(4)
}

// SetDocument sets value of Document conditional field.
func (m *MessageMediaDocument) SetDocument(value DocumentClass) {
	m.Flags.Set(0)
	m.Document = value
}

// GetDocument returns value of Document conditional field and
// boolean which is true if field was set.
func (m *MessageMediaDocument) GetDocument() (value DocumentClass, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(0) {
		return value, false
	}
	return m.Document, true
}

// SetTTLSeconds sets value of TTLSeconds conditional field.
func (m *MessageMediaDocument) SetTTLSeconds(value int) {
	m.Flags.Set(2)
	m.TTLSeconds = value
}

// GetTTLSeconds returns value of TTLSeconds conditional field and
// boolean which is true if field was set.
func (m *MessageMediaDocument) GetTTLSeconds() (value int, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(2) {
		return value, false
	}
	return m.TTLSeconds, true
}

// MessageMediaWebPage represents TL type `messageMediaWebPage#a32dd600`.
// Preview of webpage
//
// See https://core.telegram.org/constructor/messageMediaWebPage for reference.
type MessageMediaWebPage struct {
	// Webpage preview
	Webpage WebPageClass
}

// MessageMediaWebPageTypeID is TL type id of MessageMediaWebPage.
const MessageMediaWebPageTypeID = 0xa32dd600

// construct implements constructor of MessageMediaClass.
func (m MessageMediaWebPage) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaWebPage{}
)

func (m *MessageMediaWebPage) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Webpage == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaWebPage from given interface.
func (m *MessageMediaWebPage) FillFrom(from interface {
	GetWebpage() (value WebPageClass)
}) {
	m.Webpage = from.GetWebpage()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaWebPage) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaWebPage",
		ID:   MessageMediaWebPageTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Webpage",
			SchemaName: "webpage",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaWebPage) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaWebPage#a32dd600 as nil")
	}
	b.PutID(MessageMediaWebPageTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaWebPage) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaWebPage#a32dd600 as nil")
	}
	if m.Webpage == nil {
		return fmt.Errorf("unable to encode messageMediaWebPage#a32dd600: field webpage is nil")
	}
	if err := m.Webpage.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaWebPage#a32dd600: field webpage: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaWebPage) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaWebPage#a32dd600 to nil")
	}
	{
		value, err := DecodeWebPage(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaWebPage#a32dd600: field webpage: %w", err)
		}
		m.Webpage = value
	}
	return nil
}

// GetWebpage returns value of Webpage field.
func (m *MessageMediaWebPage) GetWebpage() (value WebPageClass) {
	if m == nil {
		return
	}
	return m.Webpage
}

// MessageMediaVenue represents TL type `messageMediaVenue#2ec0533f`.
// Venue
//
// See https://core.telegram.org/constructor/messageMediaVenue for reference.
type MessageMediaVenue struct {
	// Geolocation of venue
	Geo GeoPointClass
	// Venue name
	Title string
	// Address
	Address string
	// Venue provider: currently only "foursquare" needs to be supported
	Provider string
	// Venue ID in the provider's database
	VenueID string
	// Venue type in the provider's database
	VenueType string
}

// MessageMediaVenueTypeID is TL type id of MessageMediaVenue.
const MessageMediaVenueTypeID = 0x2ec0533f

// construct implements constructor of MessageMediaClass.
func (m MessageMediaVenue) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaVenue{}
)

func (m *MessageMediaVenue) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Geo == nil) {
		return false
	}
	if !(m.Title == "") {
		return false
	}
	if !(m.Address == "") {
		return false
	}
	if !(m.Provider == "") {
		return false
	}
	if !(m.VenueID == "") {
		return false
	}
	if !(m.VenueType == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaVenue from given interface.
func (m *MessageMediaVenue) FillFrom(from interface {
	GetGeo() (value GeoPointClass)
	GetTitle() (value string)
	GetAddress() (value string)
	GetProvider() (value string)
	GetVenueID() (value string)
	GetVenueType() (value string)
}) {
	m.Geo = from.GetGeo()
	m.Title = from.GetTitle()
	m.Address = from.GetAddress()
	m.Provider = from.GetProvider()
	m.VenueID = from.GetVenueID()
	m.VenueType = from.GetVenueType()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaVenue) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaVenue",
		ID:   MessageMediaVenueTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Geo",
			SchemaName: "geo",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Address",
			SchemaName: "address",
		},
		{
			Name:       "Provider",
			SchemaName: "provider",
		},
		{
			Name:       "VenueID",
			SchemaName: "venue_id",
		},
		{
			Name:       "VenueType",
			SchemaName: "venue_type",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaVenue) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaVenue#2ec0533f as nil")
	}
	b.PutID(MessageMediaVenueTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaVenue) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaVenue#2ec0533f as nil")
	}
	if m.Geo == nil {
		return fmt.Errorf("unable to encode messageMediaVenue#2ec0533f: field geo is nil")
	}
	if err := m.Geo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaVenue#2ec0533f: field geo: %w", err)
	}
	b.PutString(m.Title)
	b.PutString(m.Address)
	b.PutString(m.Provider)
	b.PutString(m.VenueID)
	b.PutString(m.VenueType)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaVenue) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaVenue#2ec0533f to nil")
	}
	{
		value, err := DecodeGeoPoint(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaVenue#2ec0533f: field geo: %w", err)
		}
		m.Geo = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaVenue#2ec0533f: field title: %w", err)
		}
		m.Title = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaVenue#2ec0533f: field address: %w", err)
		}
		m.Address = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaVenue#2ec0533f: field provider: %w", err)
		}
		m.Provider = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaVenue#2ec0533f: field venue_id: %w", err)
		}
		m.VenueID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaVenue#2ec0533f: field venue_type: %w", err)
		}
		m.VenueType = value
	}
	return nil
}

// GetGeo returns value of Geo field.
func (m *MessageMediaVenue) GetGeo() (value GeoPointClass) {
	if m == nil {
		return
	}
	return m.Geo
}

// GetTitle returns value of Title field.
func (m *MessageMediaVenue) GetTitle() (value string) {
	if m == nil {
		return
	}
	return m.Title
}

// GetAddress returns value of Address field.
func (m *MessageMediaVenue) GetAddress() (value string) {
	if m == nil {
		return
	}
	return m.Address
}

// GetProvider returns value of Provider field.
func (m *MessageMediaVenue) GetProvider() (value string) {
	if m == nil {
		return
	}
	return m.Provider
}

// GetVenueID returns value of VenueID field.
func (m *MessageMediaVenue) GetVenueID() (value string) {
	if m == nil {
		return
	}
	return m.VenueID
}

// GetVenueType returns value of VenueType field.
func (m *MessageMediaVenue) GetVenueType() (value string) {
	if m == nil {
		return
	}
	return m.VenueType
}

// MessageMediaGame represents TL type `messageMediaGame#fdb19008`.
// Telegram game
//
// See https://core.telegram.org/constructor/messageMediaGame for reference.
type MessageMediaGame struct {
	// Game
	Game Game
}

// MessageMediaGameTypeID is TL type id of MessageMediaGame.
const MessageMediaGameTypeID = 0xfdb19008

// construct implements constructor of MessageMediaClass.
func (m MessageMediaGame) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaGame{}
)

func (m *MessageMediaGame) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Game.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaGame from given interface.
func (m *MessageMediaGame) FillFrom(from interface {
	GetGame() (value Game)
}) {
	m.Game = from.GetGame()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaGame) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaGame",
		ID:   MessageMediaGameTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Game",
			SchemaName: "game",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaGame) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaGame#fdb19008 as nil")
	}
	b.PutID(MessageMediaGameTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaGame) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaGame#fdb19008 as nil")
	}
	if err := m.Game.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaGame#fdb19008: field game: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaGame) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaGame#fdb19008 to nil")
	}
	{
		if err := m.Game.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaGame#fdb19008: field game: %w", err)
		}
	}
	return nil
}

// GetGame returns value of Game field.
func (m *MessageMediaGame) GetGame() (value Game) {
	if m == nil {
		return
	}
	return m.Game
}

// MessageMediaInvoice represents TL type `messageMediaInvoice#f6a548d3`.
// Invoice
//
// See https://core.telegram.org/constructor/messageMediaInvoice for reference.
type MessageMediaInvoice struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the shipping address was requested
	ShippingAddressRequested bool
	// Whether this is an example invoice
	Test bool
	// Product name, 1-32 characters
	Title string
	// Product description, 1-255 characters
	Description string
	// URL of the product photo for the invoice. Can be a photo of the goods or a marketing
	// image for a service. People like it better when they see what they are paying for.
	//
	// Use SetPhoto and GetPhoto helpers.
	Photo WebDocumentClass
	// Message ID of receipt: if set, clients should change the text of the first
	// keyboardButtonBuy¹ button always attached to the message² to a localized version of
	// the word Receipt
	//
	// Links:
	//  1) https://core.telegram.org/constructor/keyboardButtonBuy
	//  2) https://core.telegram.org/constructor/message
	//
	// Use SetReceiptMsgID and GetReceiptMsgID helpers.
	ReceiptMsgID int
	// Three-letter ISO 4217 currency¹ code
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments#supported-currencies
	Currency string
	// Total price in the smallest units of the currency (integer, not float/double). For
	// example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in
	// currencies.json¹, it shows the number of digits past the decimal point for each
	// currency (2 for the majority of currencies).
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments/currencies.json
	TotalAmount int64
	// Unique bot deep-linking parameter that can be used to generate this invoice
	StartParam string
	// Extended media
	//
	// Use SetExtendedMedia and GetExtendedMedia helpers.
	ExtendedMedia MessageExtendedMediaClass
}

// MessageMediaInvoiceTypeID is TL type id of MessageMediaInvoice.
const MessageMediaInvoiceTypeID = 0xf6a548d3

// construct implements constructor of MessageMediaClass.
func (m MessageMediaInvoice) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaInvoice{}
)

func (m *MessageMediaInvoice) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Flags.Zero()) {
		return false
	}
	if !(m.ShippingAddressRequested == false) {
		return false
	}
	if !(m.Test == false) {
		return false
	}
	if !(m.Title == "") {
		return false
	}
	if !(m.Description == "") {
		return false
	}
	if !(m.Photo == nil) {
		return false
	}
	if !(m.ReceiptMsgID == 0) {
		return false
	}
	if !(m.Currency == "") {
		return false
	}
	if !(m.TotalAmount == 0) {
		return false
	}
	if !(m.StartParam == "") {
		return false
	}
	if !(m.ExtendedMedia == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaInvoice from given interface.
func (m *MessageMediaInvoice) FillFrom(from interface {
	GetShippingAddressRequested() (value bool)
	GetTest() (value bool)
	GetTitle() (value string)
	GetDescription() (value string)
	GetPhoto() (value WebDocumentClass, ok bool)
	GetReceiptMsgID() (value int, ok bool)
	GetCurrency() (value string)
	GetTotalAmount() (value int64)
	GetStartParam() (value string)
	GetExtendedMedia() (value MessageExtendedMediaClass, ok bool)
}) {
	m.ShippingAddressRequested = from.GetShippingAddressRequested()
	m.Test = from.GetTest()
	m.Title = from.GetTitle()
	m.Description = from.GetDescription()
	if val, ok := from.GetPhoto(); ok {
		m.Photo = val
	}

	if val, ok := from.GetReceiptMsgID(); ok {
		m.ReceiptMsgID = val
	}

	m.Currency = from.GetCurrency()
	m.TotalAmount = from.GetTotalAmount()
	m.StartParam = from.GetStartParam()
	if val, ok := from.GetExtendedMedia(); ok {
		m.ExtendedMedia = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaInvoice) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaInvoice",
		ID:   MessageMediaInvoiceTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ShippingAddressRequested",
			SchemaName: "shipping_address_requested",
			Null:       !m.Flags.Has(1),
		},
		{
			Name:       "Test",
			SchemaName: "test",
			Null:       !m.Flags.Has(3),
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Description",
			SchemaName: "description",
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
			Null:       !m.Flags.Has(0),
		},
		{
			Name:       "ReceiptMsgID",
			SchemaName: "receipt_msg_id",
			Null:       !m.Flags.Has(2),
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "TotalAmount",
			SchemaName: "total_amount",
		},
		{
			Name:       "StartParam",
			SchemaName: "start_param",
		},
		{
			Name:       "ExtendedMedia",
			SchemaName: "extended_media",
			Null:       !m.Flags.Has(4),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (m *MessageMediaInvoice) SetFlags() {
	if !(m.ShippingAddressRequested == false) {
		m.Flags.Set(1)
	}
	if !(m.Test == false) {
		m.Flags.Set(3)
	}
	if !(m.Photo == nil) {
		m.Flags.Set(0)
	}
	if !(m.ReceiptMsgID == 0) {
		m.Flags.Set(2)
	}
	if !(m.ExtendedMedia == nil) {
		m.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func (m *MessageMediaInvoice) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaInvoice#f6a548d3 as nil")
	}
	b.PutID(MessageMediaInvoiceTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaInvoice) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaInvoice#f6a548d3 as nil")
	}
	m.SetFlags()
	if err := m.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaInvoice#f6a548d3: field flags: %w", err)
	}
	b.PutString(m.Title)
	b.PutString(m.Description)
	if m.Flags.Has(0) {
		if m.Photo == nil {
			return fmt.Errorf("unable to encode messageMediaInvoice#f6a548d3: field photo is nil")
		}
		if err := m.Photo.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messageMediaInvoice#f6a548d3: field photo: %w", err)
		}
	}
	if m.Flags.Has(2) {
		b.PutInt(m.ReceiptMsgID)
	}
	b.PutString(m.Currency)
	b.PutLong(m.TotalAmount)
	b.PutString(m.StartParam)
	if m.Flags.Has(4) {
		if m.ExtendedMedia == nil {
			return fmt.Errorf("unable to encode messageMediaInvoice#f6a548d3: field extended_media is nil")
		}
		if err := m.ExtendedMedia.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messageMediaInvoice#f6a548d3: field extended_media: %w", err)
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaInvoice) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaInvoice#f6a548d3 to nil")
	}
	{
		if err := m.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field flags: %w", err)
		}
	}
	m.ShippingAddressRequested = m.Flags.Has(1)
	m.Test = m.Flags.Has(3)
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field title: %w", err)
		}
		m.Title = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field description: %w", err)
		}
		m.Description = value
	}
	if m.Flags.Has(0) {
		value, err := DecodeWebDocument(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field photo: %w", err)
		}
		m.Photo = value
	}
	if m.Flags.Has(2) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field receipt_msg_id: %w", err)
		}
		m.ReceiptMsgID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field currency: %w", err)
		}
		m.Currency = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field total_amount: %w", err)
		}
		m.TotalAmount = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field start_param: %w", err)
		}
		m.StartParam = value
	}
	if m.Flags.Has(4) {
		value, err := DecodeMessageExtendedMedia(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaInvoice#f6a548d3: field extended_media: %w", err)
		}
		m.ExtendedMedia = value
	}
	return nil
}

// SetShippingAddressRequested sets value of ShippingAddressRequested conditional field.
func (m *MessageMediaInvoice) SetShippingAddressRequested(value bool) {
	if value {
		m.Flags.Set(1)
		m.ShippingAddressRequested = true
	} else {
		m.Flags.Unset(1)
		m.ShippingAddressRequested = false
	}
}

// GetShippingAddressRequested returns value of ShippingAddressRequested conditional field.
func (m *MessageMediaInvoice) GetShippingAddressRequested() (value bool) {
	if m == nil {
		return
	}
	return m.Flags.Has(1)
}

// SetTest sets value of Test conditional field.
func (m *MessageMediaInvoice) SetTest(value bool) {
	if value {
		m.Flags.Set(3)
		m.Test = true
	} else {
		m.Flags.Unset(3)
		m.Test = false
	}
}

// GetTest returns value of Test conditional field.
func (m *MessageMediaInvoice) GetTest() (value bool) {
	if m == nil {
		return
	}
	return m.Flags.Has(3)
}

// GetTitle returns value of Title field.
func (m *MessageMediaInvoice) GetTitle() (value string) {
	if m == nil {
		return
	}
	return m.Title
}

// GetDescription returns value of Description field.
func (m *MessageMediaInvoice) GetDescription() (value string) {
	if m == nil {
		return
	}
	return m.Description
}

// SetPhoto sets value of Photo conditional field.
func (m *MessageMediaInvoice) SetPhoto(value WebDocumentClass) {
	m.Flags.Set(0)
	m.Photo = value
}

// GetPhoto returns value of Photo conditional field and
// boolean which is true if field was set.
func (m *MessageMediaInvoice) GetPhoto() (value WebDocumentClass, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(0) {
		return value, false
	}
	return m.Photo, true
}

// SetReceiptMsgID sets value of ReceiptMsgID conditional field.
func (m *MessageMediaInvoice) SetReceiptMsgID(value int) {
	m.Flags.Set(2)
	m.ReceiptMsgID = value
}

// GetReceiptMsgID returns value of ReceiptMsgID conditional field and
// boolean which is true if field was set.
func (m *MessageMediaInvoice) GetReceiptMsgID() (value int, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(2) {
		return value, false
	}
	return m.ReceiptMsgID, true
}

// GetCurrency returns value of Currency field.
func (m *MessageMediaInvoice) GetCurrency() (value string) {
	if m == nil {
		return
	}
	return m.Currency
}

// GetTotalAmount returns value of TotalAmount field.
func (m *MessageMediaInvoice) GetTotalAmount() (value int64) {
	if m == nil {
		return
	}
	return m.TotalAmount
}

// GetStartParam returns value of StartParam field.
func (m *MessageMediaInvoice) GetStartParam() (value string) {
	if m == nil {
		return
	}
	return m.StartParam
}

// SetExtendedMedia sets value of ExtendedMedia conditional field.
func (m *MessageMediaInvoice) SetExtendedMedia(value MessageExtendedMediaClass) {
	m.Flags.Set(4)
	m.ExtendedMedia = value
}

// GetExtendedMedia returns value of ExtendedMedia conditional field and
// boolean which is true if field was set.
func (m *MessageMediaInvoice) GetExtendedMedia() (value MessageExtendedMediaClass, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(4) {
		return value, false
	}
	return m.ExtendedMedia, true
}

// MessageMediaGeoLive represents TL type `messageMediaGeoLive#b940c666`.
// Indicates a live geolocation¹
//
// Links:
//  1. https://core.telegram.org/api/live-location
//
// See https://core.telegram.org/constructor/messageMediaGeoLive for reference.
type MessageMediaGeoLive struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Geolocation
	Geo GeoPointClass
	// For live locations¹, a direction in which the location moves, in degrees; 1-360
	//
	// Links:
	//  1) https://core.telegram.org/api/live-location
	//
	// Use SetHeading and GetHeading helpers.
	Heading int
	// Validity period of provided geolocation
	Period int
	// For live locations¹, a maximum distance to another chat member for proximity alerts,
	// in meters (0-100000).
	//
	// Links:
	//  1) https://core.telegram.org/api/live-location
	//
	// Use SetProximityNotificationRadius and GetProximityNotificationRadius helpers.
	ProximityNotificationRadius int
}

// MessageMediaGeoLiveTypeID is TL type id of MessageMediaGeoLive.
const MessageMediaGeoLiveTypeID = 0xb940c666

// construct implements constructor of MessageMediaClass.
func (m MessageMediaGeoLive) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaGeoLive{}
)

func (m *MessageMediaGeoLive) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Flags.Zero()) {
		return false
	}
	if !(m.Geo == nil) {
		return false
	}
	if !(m.Heading == 0) {
		return false
	}
	if !(m.Period == 0) {
		return false
	}
	if !(m.ProximityNotificationRadius == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaGeoLive from given interface.
func (m *MessageMediaGeoLive) FillFrom(from interface {
	GetGeo() (value GeoPointClass)
	GetHeading() (value int, ok bool)
	GetPeriod() (value int)
	GetProximityNotificationRadius() (value int, ok bool)
}) {
	m.Geo = from.GetGeo()
	if val, ok := from.GetHeading(); ok {
		m.Heading = val
	}

	m.Period = from.GetPeriod()
	if val, ok := from.GetProximityNotificationRadius(); ok {
		m.ProximityNotificationRadius = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaGeoLive) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaGeoLive",
		ID:   MessageMediaGeoLiveTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Geo",
			SchemaName: "geo",
		},
		{
			Name:       "Heading",
			SchemaName: "heading",
			Null:       !m.Flags.Has(0),
		},
		{
			Name:       "Period",
			SchemaName: "period",
		},
		{
			Name:       "ProximityNotificationRadius",
			SchemaName: "proximity_notification_radius",
			Null:       !m.Flags.Has(1),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (m *MessageMediaGeoLive) SetFlags() {
	if !(m.Heading == 0) {
		m.Flags.Set(0)
	}
	if !(m.ProximityNotificationRadius == 0) {
		m.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func (m *MessageMediaGeoLive) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaGeoLive#b940c666 as nil")
	}
	b.PutID(MessageMediaGeoLiveTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaGeoLive) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaGeoLive#b940c666 as nil")
	}
	m.SetFlags()
	if err := m.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaGeoLive#b940c666: field flags: %w", err)
	}
	if m.Geo == nil {
		return fmt.Errorf("unable to encode messageMediaGeoLive#b940c666: field geo is nil")
	}
	if err := m.Geo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaGeoLive#b940c666: field geo: %w", err)
	}
	if m.Flags.Has(0) {
		b.PutInt(m.Heading)
	}
	b.PutInt(m.Period)
	if m.Flags.Has(1) {
		b.PutInt(m.ProximityNotificationRadius)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaGeoLive) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaGeoLive#b940c666 to nil")
	}
	{
		if err := m.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaGeoLive#b940c666: field flags: %w", err)
		}
	}
	{
		value, err := DecodeGeoPoint(b)
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaGeoLive#b940c666: field geo: %w", err)
		}
		m.Geo = value
	}
	if m.Flags.Has(0) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaGeoLive#b940c666: field heading: %w", err)
		}
		m.Heading = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaGeoLive#b940c666: field period: %w", err)
		}
		m.Period = value
	}
	if m.Flags.Has(1) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaGeoLive#b940c666: field proximity_notification_radius: %w", err)
		}
		m.ProximityNotificationRadius = value
	}
	return nil
}

// GetGeo returns value of Geo field.
func (m *MessageMediaGeoLive) GetGeo() (value GeoPointClass) {
	if m == nil {
		return
	}
	return m.Geo
}

// SetHeading sets value of Heading conditional field.
func (m *MessageMediaGeoLive) SetHeading(value int) {
	m.Flags.Set(0)
	m.Heading = value
}

// GetHeading returns value of Heading conditional field and
// boolean which is true if field was set.
func (m *MessageMediaGeoLive) GetHeading() (value int, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(0) {
		return value, false
	}
	return m.Heading, true
}

// GetPeriod returns value of Period field.
func (m *MessageMediaGeoLive) GetPeriod() (value int) {
	if m == nil {
		return
	}
	return m.Period
}

// SetProximityNotificationRadius sets value of ProximityNotificationRadius conditional field.
func (m *MessageMediaGeoLive) SetProximityNotificationRadius(value int) {
	m.Flags.Set(1)
	m.ProximityNotificationRadius = value
}

// GetProximityNotificationRadius returns value of ProximityNotificationRadius conditional field and
// boolean which is true if field was set.
func (m *MessageMediaGeoLive) GetProximityNotificationRadius() (value int, ok bool) {
	if m == nil {
		return
	}
	if !m.Flags.Has(1) {
		return value, false
	}
	return m.ProximityNotificationRadius, true
}

// MessageMediaPoll represents TL type `messageMediaPoll#4bd6e798`.
// Poll
//
// See https://core.telegram.org/constructor/messageMediaPoll for reference.
type MessageMediaPoll struct {
	// The poll
	Poll Poll
	// The results of the poll
	Results PollResults
}

// MessageMediaPollTypeID is TL type id of MessageMediaPoll.
const MessageMediaPollTypeID = 0x4bd6e798

// construct implements constructor of MessageMediaClass.
func (m MessageMediaPoll) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaPoll{}
)

func (m *MessageMediaPoll) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Poll.Zero()) {
		return false
	}
	if !(m.Results.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaPoll from given interface.
func (m *MessageMediaPoll) FillFrom(from interface {
	GetPoll() (value Poll)
	GetResults() (value PollResults)
}) {
	m.Poll = from.GetPoll()
	m.Results = from.GetResults()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaPoll) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaPoll",
		ID:   MessageMediaPollTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Poll",
			SchemaName: "poll",
		},
		{
			Name:       "Results",
			SchemaName: "results",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaPoll) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaPoll#4bd6e798 as nil")
	}
	b.PutID(MessageMediaPollTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaPoll) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaPoll#4bd6e798 as nil")
	}
	if err := m.Poll.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaPoll#4bd6e798: field poll: %w", err)
	}
	if err := m.Results.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageMediaPoll#4bd6e798: field results: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaPoll) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaPoll#4bd6e798 to nil")
	}
	if err := b.ConsumeID(MessageMediaPollTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaPoll#4bd6e798: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaPoll) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaPoll#4bd6e798 to nil")
	}
	{
		if err := m.Poll.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaPoll#4bd6e798: field poll: %w", err)
		}
	}
	{
		if err := m.Results.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageMediaPoll#4bd6e798: field results: %w", err)
		}
	}
	return nil
}

// GetPoll returns value of Poll field.
func (m *MessageMediaPoll) GetPoll() (value Poll) {
	if m == nil {
		return
	}
	return m.Poll
}

// GetResults returns value of Results field.
func (m *MessageMediaPoll) GetResults() (value PollResults) {
	if m == nil {
		return
	}
	return m.Results
}

// MessageMediaDice represents TL type `messageMediaDice#3f7ee58b`.
// Dice-based animated sticker¹
//
// Links:
//  1. https://core.telegram.org/api/dice
//
// See https://core.telegram.org/constructor/messageMediaDice for reference.
type MessageMediaDice struct {
	// Dice value¹
	//
	// Links:
	//  1) https://core.telegram.org/api/dice
	Value int
	// The emoji, for now ,  and  are supported
	Emoticon string
}

// MessageMediaDiceTypeID is TL type id of MessageMediaDice.
const MessageMediaDiceTypeID = 0x3f7ee58b

// construct implements constructor of MessageMediaClass.
func (m MessageMediaDice) construct() MessageMediaClass { return &m }

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

	_ MessageMediaClass = &MessageMediaDice{}
)

func (m *MessageMediaDice) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Value == 0) {
		return false
	}
	if !(m.Emoticon == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessageMediaDice from given interface.
func (m *MessageMediaDice) FillFrom(from interface {
	GetValue() (value int)
	GetEmoticon() (value string)
}) {
	m.Value = from.GetValue()
	m.Emoticon = from.GetEmoticon()
}

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

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

// TypeInfo returns info about TL type.
func (m *MessageMediaDice) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageMediaDice",
		ID:   MessageMediaDiceTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Value",
			SchemaName: "value",
		},
		{
			Name:       "Emoticon",
			SchemaName: "emoticon",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageMediaDice) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaDice#3f7ee58b as nil")
	}
	b.PutID(MessageMediaDiceTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaDice) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageMediaDice#3f7ee58b as nil")
	}
	b.PutInt(m.Value)
	b.PutString(m.Emoticon)
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageMediaDice) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaDice#3f7ee58b to nil")
	}
	if err := b.ConsumeID(MessageMediaDiceTypeID); err != nil {
		return fmt.Errorf("unable to decode messageMediaDice#3f7ee58b: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaDice) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageMediaDice#3f7ee58b to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaDice#3f7ee58b: field value: %w", err)
		}
		m.Value = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messageMediaDice#3f7ee58b: field emoticon: %w", err)
		}
		m.Emoticon = value
	}
	return nil
}

// GetValue returns value of Value field.
func (m *MessageMediaDice) GetValue() (value int) {
	if m == nil {
		return
	}
	return m.Value
}

// GetEmoticon returns value of Emoticon field.
func (m *MessageMediaDice) GetEmoticon() (value string) {
	if m == nil {
		return
	}
	return m.Emoticon
}

// MessageMediaClassName is schema name of MessageMediaClass.
const MessageMediaClassName = "MessageMedia"

// MessageMediaClass represents MessageMedia generic type.
//
// See https://core.telegram.org/type/MessageMedia for reference.
//
// Example:
//
//	g, err := tg.DecodeMessageMedia(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessageMediaEmpty: // messageMediaEmpty#3ded6320
//	case *tg.MessageMediaPhoto: // messageMediaPhoto#695150d7
//	case *tg.MessageMediaGeo: // messageMediaGeo#56e0d474
//	case *tg.MessageMediaContact: // messageMediaContact#70322949
//	case *tg.MessageMediaUnsupported: // messageMediaUnsupported#9f84f49e
//	case *tg.MessageMediaDocument: // messageMediaDocument#9cb070d7
//	case *tg.MessageMediaWebPage: // messageMediaWebPage#a32dd600
//	case *tg.MessageMediaVenue: // messageMediaVenue#2ec0533f
//	case *tg.MessageMediaGame: // messageMediaGame#fdb19008
//	case *tg.MessageMediaInvoice: // messageMediaInvoice#f6a548d3
//	case *tg.MessageMediaGeoLive: // messageMediaGeoLive#b940c666
//	case *tg.MessageMediaPoll: // messageMediaPoll#4bd6e798
//	case *tg.MessageMediaDice: // messageMediaDice#3f7ee58b
//	default: panic(v)
//	}
type MessageMediaClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessageMediaClass

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

// DecodeMessageMedia implements binary de-serialization for MessageMediaClass.
func DecodeMessageMedia(buf *bin.Buffer) (MessageMediaClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case MessageMediaEmptyTypeID:
		// Decoding messageMediaEmpty#3ded6320.
		v := MessageMediaEmpty{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaPhotoTypeID:
		// Decoding messageMediaPhoto#695150d7.
		v := MessageMediaPhoto{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaGeoTypeID:
		// Decoding messageMediaGeo#56e0d474.
		v := MessageMediaGeo{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaContactTypeID:
		// Decoding messageMediaContact#70322949.
		v := MessageMediaContact{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaUnsupportedTypeID:
		// Decoding messageMediaUnsupported#9f84f49e.
		v := MessageMediaUnsupported{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaDocumentTypeID:
		// Decoding messageMediaDocument#9cb070d7.
		v := MessageMediaDocument{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaWebPageTypeID:
		// Decoding messageMediaWebPage#a32dd600.
		v := MessageMediaWebPage{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaVenueTypeID:
		// Decoding messageMediaVenue#2ec0533f.
		v := MessageMediaVenue{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaGameTypeID:
		// Decoding messageMediaGame#fdb19008.
		v := MessageMediaGame{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaInvoiceTypeID:
		// Decoding messageMediaInvoice#f6a548d3.
		v := MessageMediaInvoice{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaGeoLiveTypeID:
		// Decoding messageMediaGeoLive#b940c666.
		v := MessageMediaGeoLive{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaPollTypeID:
		// Decoding messageMediaPoll#4bd6e798.
		v := MessageMediaPoll{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	case MessageMediaDiceTypeID:
		// Decoding messageMediaDice#3f7ee58b.
		v := MessageMediaDice{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", bin.NewUnexpectedID(id))
	}
}

// MessageMedia boxes the MessageMediaClass providing a helper.
type MessageMediaBox struct {
	MessageMedia MessageMediaClass
}

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

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