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

// StoryAreaTypeLocation represents TL type `storyAreaTypeLocation#a8b3caa3`.
type StoryAreaTypeLocation struct {
	// The location
	Location Location
	// Address of the location; may be null if unknown
	Address LocationAddress
}

// StoryAreaTypeLocationTypeID is TL type id of StoryAreaTypeLocation.
const StoryAreaTypeLocationTypeID = 0xa8b3caa3

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeLocation) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeLocation{}
)

func (s *StoryAreaTypeLocation) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Location.Zero()) {
		return false
	}
	if !(s.Address.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeLocation) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeLocation",
		ID:   StoryAreaTypeLocationTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Location",
			SchemaName: "location",
		},
		{
			Name:       "Address",
			SchemaName: "address",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeLocation) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeLocation#a8b3caa3 as nil")
	}
	b.PutID(StoryAreaTypeLocationTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeLocation) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeLocation#a8b3caa3 as nil")
	}
	if err := s.Location.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeLocation#a8b3caa3: field location: %w", err)
	}
	if err := s.Address.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeLocation#a8b3caa3: field address: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeLocation) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeLocation#a8b3caa3 to nil")
	}
	{
		if err := s.Location.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeLocation#a8b3caa3: field location: %w", err)
		}
	}
	{
		if err := s.Address.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeLocation#a8b3caa3: field address: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeLocation) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeLocation#a8b3caa3 as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeLocation")
	b.Comma()
	b.FieldStart("location")
	if err := s.Location.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeLocation#a8b3caa3: field location: %w", err)
	}
	b.Comma()
	b.FieldStart("address")
	if err := s.Address.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeLocation#a8b3caa3: field address: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storyAreaTypeLocation"); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeLocation#a8b3caa3: %w", err)
			}
		case "location":
			if err := s.Location.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeLocation#a8b3caa3: field location: %w", err)
			}
		case "address":
			if err := s.Address.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeLocation#a8b3caa3: field address: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLocation returns value of Location field.
func (s *StoryAreaTypeLocation) GetLocation() (value Location) {
	if s == nil {
		return
	}
	return s.Location
}

// GetAddress returns value of Address field.
func (s *StoryAreaTypeLocation) GetAddress() (value LocationAddress) {
	if s == nil {
		return
	}
	return s.Address
}

// StoryAreaTypeVenue represents TL type `storyAreaTypeVenue#18ae4d06`.
type StoryAreaTypeVenue struct {
	// Information about the venue
	Venue Venue
}

// StoryAreaTypeVenueTypeID is TL type id of StoryAreaTypeVenue.
const StoryAreaTypeVenueTypeID = 0x18ae4d06

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeVenue) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeVenue{}
)

func (s *StoryAreaTypeVenue) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Venue.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeVenue) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeVenue",
		ID:   StoryAreaTypeVenueTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Venue",
			SchemaName: "venue",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeVenue) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeVenue#18ae4d06 as nil")
	}
	b.PutID(StoryAreaTypeVenueTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeVenue) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeVenue#18ae4d06 as nil")
	}
	if err := s.Venue.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeVenue#18ae4d06: field venue: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *StoryAreaTypeVenue) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeVenue#18ae4d06 to nil")
	}
	if err := b.ConsumeID(StoryAreaTypeVenueTypeID); err != nil {
		return fmt.Errorf("unable to decode storyAreaTypeVenue#18ae4d06: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeVenue) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeVenue#18ae4d06 to nil")
	}
	{
		if err := s.Venue.Decode(b); err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeVenue#18ae4d06: field venue: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeVenue) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeVenue#18ae4d06 as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeVenue")
	b.Comma()
	b.FieldStart("venue")
	if err := s.Venue.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeVenue#18ae4d06: field venue: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StoryAreaTypeVenue) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeVenue#18ae4d06 to nil")
	}

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

// GetVenue returns value of Venue field.
func (s *StoryAreaTypeVenue) GetVenue() (value Venue) {
	if s == nil {
		return
	}
	return s.Venue
}

// StoryAreaTypeSuggestedReaction represents TL type `storyAreaTypeSuggestedReaction#f95f927c`.
type StoryAreaTypeSuggestedReaction struct {
	// Type of the reaction
	ReactionType ReactionTypeClass
	// Number of times the reaction was added
	TotalCount int32
	// True, if reaction has a dark background
	IsDark bool
	// True, if reaction corner is flipped
	IsFlipped bool
}

// StoryAreaTypeSuggestedReactionTypeID is TL type id of StoryAreaTypeSuggestedReaction.
const StoryAreaTypeSuggestedReactionTypeID = 0xf95f927c

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeSuggestedReaction) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeSuggestedReaction{}
)

func (s *StoryAreaTypeSuggestedReaction) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ReactionType == nil) {
		return false
	}
	if !(s.TotalCount == 0) {
		return false
	}
	if !(s.IsDark == false) {
		return false
	}
	if !(s.IsFlipped == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeSuggestedReaction) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeSuggestedReaction",
		ID:   StoryAreaTypeSuggestedReactionTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ReactionType",
			SchemaName: "reaction_type",
		},
		{
			Name:       "TotalCount",
			SchemaName: "total_count",
		},
		{
			Name:       "IsDark",
			SchemaName: "is_dark",
		},
		{
			Name:       "IsFlipped",
			SchemaName: "is_flipped",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeSuggestedReaction) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeSuggestedReaction#f95f927c as nil")
	}
	b.PutID(StoryAreaTypeSuggestedReactionTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeSuggestedReaction) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeSuggestedReaction#f95f927c as nil")
	}
	if s.ReactionType == nil {
		return fmt.Errorf("unable to encode storyAreaTypeSuggestedReaction#f95f927c: field reaction_type is nil")
	}
	if err := s.ReactionType.Encode(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeSuggestedReaction#f95f927c: field reaction_type: %w", err)
	}
	b.PutInt32(s.TotalCount)
	b.PutBool(s.IsDark)
	b.PutBool(s.IsFlipped)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeSuggestedReaction) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeSuggestedReaction#f95f927c to nil")
	}
	{
		value, err := DecodeReactionType(b)
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field reaction_type: %w", err)
		}
		s.ReactionType = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field total_count: %w", err)
		}
		s.TotalCount = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field is_dark: %w", err)
		}
		s.IsDark = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field is_flipped: %w", err)
		}
		s.IsFlipped = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeSuggestedReaction) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeSuggestedReaction#f95f927c as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeSuggestedReaction")
	b.Comma()
	b.FieldStart("reaction_type")
	if s.ReactionType == nil {
		return fmt.Errorf("unable to encode storyAreaTypeSuggestedReaction#f95f927c: field reaction_type is nil")
	}
	if err := s.ReactionType.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode storyAreaTypeSuggestedReaction#f95f927c: field reaction_type: %w", err)
	}
	b.Comma()
	b.FieldStart("total_count")
	b.PutInt32(s.TotalCount)
	b.Comma()
	b.FieldStart("is_dark")
	b.PutBool(s.IsDark)
	b.Comma()
	b.FieldStart("is_flipped")
	b.PutBool(s.IsFlipped)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storyAreaTypeSuggestedReaction"); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: %w", err)
			}
		case "reaction_type":
			value, err := DecodeTDLibJSONReactionType(b)
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field reaction_type: %w", err)
			}
			s.ReactionType = value
		case "total_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field total_count: %w", err)
			}
			s.TotalCount = value
		case "is_dark":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field is_dark: %w", err)
			}
			s.IsDark = value
		case "is_flipped":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeSuggestedReaction#f95f927c: field is_flipped: %w", err)
			}
			s.IsFlipped = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetReactionType returns value of ReactionType field.
func (s *StoryAreaTypeSuggestedReaction) GetReactionType() (value ReactionTypeClass) {
	if s == nil {
		return
	}
	return s.ReactionType
}

// GetTotalCount returns value of TotalCount field.
func (s *StoryAreaTypeSuggestedReaction) GetTotalCount() (value int32) {
	if s == nil {
		return
	}
	return s.TotalCount
}

// GetIsDark returns value of IsDark field.
func (s *StoryAreaTypeSuggestedReaction) GetIsDark() (value bool) {
	if s == nil {
		return
	}
	return s.IsDark
}

// GetIsFlipped returns value of IsFlipped field.
func (s *StoryAreaTypeSuggestedReaction) GetIsFlipped() (value bool) {
	if s == nil {
		return
	}
	return s.IsFlipped
}

// StoryAreaTypeMessage represents TL type `storyAreaTypeMessage#bfef76b4`.
type StoryAreaTypeMessage struct {
	// Identifier of the chat with the message
	ChatID int64
	// Identifier of the message
	MessageID int64
}

// StoryAreaTypeMessageTypeID is TL type id of StoryAreaTypeMessage.
const StoryAreaTypeMessageTypeID = 0xbfef76b4

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeMessage) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeMessage{}
)

func (s *StoryAreaTypeMessage) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.MessageID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeMessage) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeMessage",
		ID:   StoryAreaTypeMessageTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeMessage) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeMessage#bfef76b4 as nil")
	}
	b.PutID(StoryAreaTypeMessageTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeMessage) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeMessage#bfef76b4 as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt53(s.MessageID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeMessage) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeMessage#bfef76b4 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeMessage#bfef76b4: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeMessage#bfef76b4: field message_id: %w", err)
		}
		s.MessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeMessage) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeMessage#bfef76b4 as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeMessage")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(s.MessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storyAreaTypeMessage"); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeMessage#bfef76b4: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeMessage#bfef76b4: field chat_id: %w", err)
			}
			s.ChatID = value
		case "message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeMessage#bfef76b4: field message_id: %w", err)
			}
			s.MessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (s *StoryAreaTypeMessage) GetChatID() (value int64) {
	if s == nil {
		return
	}
	return s.ChatID
}

// GetMessageID returns value of MessageID field.
func (s *StoryAreaTypeMessage) GetMessageID() (value int64) {
	if s == nil {
		return
	}
	return s.MessageID
}

// StoryAreaTypeLink represents TL type `storyAreaTypeLink#f8626185`.
type StoryAreaTypeLink struct {
	// HTTP or tg:// URL to be opened when the area is clicked
	URL string
}

// StoryAreaTypeLinkTypeID is TL type id of StoryAreaTypeLink.
const StoryAreaTypeLinkTypeID = 0xf8626185

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeLink) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeLink{}
)

func (s *StoryAreaTypeLink) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.URL == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeLink) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeLink",
		ID:   StoryAreaTypeLinkTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeLink) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeLink#f8626185 as nil")
	}
	b.PutID(StoryAreaTypeLinkTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeLink) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeLink#f8626185 as nil")
	}
	b.PutString(s.URL)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeLink) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeLink#f8626185 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeLink#f8626185: field url: %w", err)
		}
		s.URL = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeLink) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeLink#f8626185 as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeLink")
	b.Comma()
	b.FieldStart("url")
	b.PutString(s.URL)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

// StoryAreaTypeWeather represents TL type `storyAreaTypeWeather#a6587dbe`.
type StoryAreaTypeWeather struct {
	// Temperature, in degree Celsius
	Temperature float64
	// Emoji representing the weather
	Emoji string
	// A color of the area background in the ARGB format
	BackgroundColor int32
}

// StoryAreaTypeWeatherTypeID is TL type id of StoryAreaTypeWeather.
const StoryAreaTypeWeatherTypeID = 0xa6587dbe

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeWeather) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeWeather{}
)

func (s *StoryAreaTypeWeather) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Temperature == 0) {
		return false
	}
	if !(s.Emoji == "") {
		return false
	}
	if !(s.BackgroundColor == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeWeather) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeWeather",
		ID:   StoryAreaTypeWeatherTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Temperature",
			SchemaName: "temperature",
		},
		{
			Name:       "Emoji",
			SchemaName: "emoji",
		},
		{
			Name:       "BackgroundColor",
			SchemaName: "background_color",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeWeather) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeWeather#a6587dbe as nil")
	}
	b.PutID(StoryAreaTypeWeatherTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeWeather) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeWeather#a6587dbe as nil")
	}
	b.PutDouble(s.Temperature)
	b.PutString(s.Emoji)
	b.PutInt32(s.BackgroundColor)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeWeather) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeWeather#a6587dbe to nil")
	}
	{
		value, err := b.Double()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: field temperature: %w", err)
		}
		s.Temperature = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: field emoji: %w", err)
		}
		s.Emoji = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: field background_color: %w", err)
		}
		s.BackgroundColor = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeWeather) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeWeather#a6587dbe as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeWeather")
	b.Comma()
	b.FieldStart("temperature")
	b.PutDouble(s.Temperature)
	b.Comma()
	b.FieldStart("emoji")
	b.PutString(s.Emoji)
	b.Comma()
	b.FieldStart("background_color")
	b.PutInt32(s.BackgroundColor)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storyAreaTypeWeather"); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: %w", err)
			}
		case "temperature":
			value, err := b.Double()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: field temperature: %w", err)
			}
			s.Temperature = value
		case "emoji":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: field emoji: %w", err)
			}
			s.Emoji = value
		case "background_color":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeWeather#a6587dbe: field background_color: %w", err)
			}
			s.BackgroundColor = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTemperature returns value of Temperature field.
func (s *StoryAreaTypeWeather) GetTemperature() (value float64) {
	if s == nil {
		return
	}
	return s.Temperature
}

// GetEmoji returns value of Emoji field.
func (s *StoryAreaTypeWeather) GetEmoji() (value string) {
	if s == nil {
		return
	}
	return s.Emoji
}

// GetBackgroundColor returns value of BackgroundColor field.
func (s *StoryAreaTypeWeather) GetBackgroundColor() (value int32) {
	if s == nil {
		return
	}
	return s.BackgroundColor
}

// StoryAreaTypeUpgradedGift represents TL type `storyAreaTypeUpgradedGift#2d50f987`.
type StoryAreaTypeUpgradedGift struct {
	// Unique name of the upgraded gift
	GiftName string
}

// StoryAreaTypeUpgradedGiftTypeID is TL type id of StoryAreaTypeUpgradedGift.
const StoryAreaTypeUpgradedGiftTypeID = 0x2d50f987

// construct implements constructor of StoryAreaTypeClass.
func (s StoryAreaTypeUpgradedGift) construct() StoryAreaTypeClass { return &s }

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

	_ StoryAreaTypeClass = &StoryAreaTypeUpgradedGift{}
)

func (s *StoryAreaTypeUpgradedGift) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.GiftName == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StoryAreaTypeUpgradedGift) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "storyAreaTypeUpgradedGift",
		ID:   StoryAreaTypeUpgradedGiftTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GiftName",
			SchemaName: "gift_name",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StoryAreaTypeUpgradedGift) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeUpgradedGift#2d50f987 as nil")
	}
	b.PutID(StoryAreaTypeUpgradedGiftTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StoryAreaTypeUpgradedGift) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeUpgradedGift#2d50f987 as nil")
	}
	b.PutString(s.GiftName)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StoryAreaTypeUpgradedGift) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeUpgradedGift#2d50f987 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode storyAreaTypeUpgradedGift#2d50f987: field gift_name: %w", err)
		}
		s.GiftName = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StoryAreaTypeUpgradedGift) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode storyAreaTypeUpgradedGift#2d50f987 as nil")
	}
	b.ObjStart()
	b.PutID("storyAreaTypeUpgradedGift")
	b.Comma()
	b.FieldStart("gift_name")
	b.PutString(s.GiftName)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StoryAreaTypeUpgradedGift) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode storyAreaTypeUpgradedGift#2d50f987 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("storyAreaTypeUpgradedGift"); err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeUpgradedGift#2d50f987: %w", err)
			}
		case "gift_name":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode storyAreaTypeUpgradedGift#2d50f987: field gift_name: %w", err)
			}
			s.GiftName = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetGiftName returns value of GiftName field.
func (s *StoryAreaTypeUpgradedGift) GetGiftName() (value string) {
	if s == nil {
		return
	}
	return s.GiftName
}

// StoryAreaTypeClassName is schema name of StoryAreaTypeClass.
const StoryAreaTypeClassName = "StoryAreaType"

// StoryAreaTypeClass represents StoryAreaType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeStoryAreaType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.StoryAreaTypeLocation: // storyAreaTypeLocation#a8b3caa3
//	case *tdapi.StoryAreaTypeVenue: // storyAreaTypeVenue#18ae4d06
//	case *tdapi.StoryAreaTypeSuggestedReaction: // storyAreaTypeSuggestedReaction#f95f927c
//	case *tdapi.StoryAreaTypeMessage: // storyAreaTypeMessage#bfef76b4
//	case *tdapi.StoryAreaTypeLink: // storyAreaTypeLink#f8626185
//	case *tdapi.StoryAreaTypeWeather: // storyAreaTypeWeather#a6587dbe
//	case *tdapi.StoryAreaTypeUpgradedGift: // storyAreaTypeUpgradedGift#2d50f987
//	default: panic(v)
//	}
type StoryAreaTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StoryAreaTypeClass

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

// DecodeStoryAreaType implements binary de-serialization for StoryAreaTypeClass.
func DecodeStoryAreaType(buf *bin.Buffer) (StoryAreaTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case StoryAreaTypeLocationTypeID:
		// Decoding storyAreaTypeLocation#a8b3caa3.
		v := StoryAreaTypeLocation{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case StoryAreaTypeVenueTypeID:
		// Decoding storyAreaTypeVenue#18ae4d06.
		v := StoryAreaTypeVenue{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case StoryAreaTypeSuggestedReactionTypeID:
		// Decoding storyAreaTypeSuggestedReaction#f95f927c.
		v := StoryAreaTypeSuggestedReaction{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case StoryAreaTypeMessageTypeID:
		// Decoding storyAreaTypeMessage#bfef76b4.
		v := StoryAreaTypeMessage{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case StoryAreaTypeLinkTypeID:
		// Decoding storyAreaTypeLink#f8626185.
		v := StoryAreaTypeLink{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case StoryAreaTypeWeatherTypeID:
		// Decoding storyAreaTypeWeather#a6587dbe.
		v := StoryAreaTypeWeather{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case StoryAreaTypeUpgradedGiftTypeID:
		// Decoding storyAreaTypeUpgradedGift#2d50f987.
		v := StoryAreaTypeUpgradedGift{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONStoryAreaType implements binary de-serialization for StoryAreaTypeClass.
func DecodeTDLibJSONStoryAreaType(buf tdjson.Decoder) (StoryAreaTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "storyAreaTypeLocation":
		// Decoding storyAreaTypeLocation#a8b3caa3.
		v := StoryAreaTypeLocation{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case "storyAreaTypeVenue":
		// Decoding storyAreaTypeVenue#18ae4d06.
		v := StoryAreaTypeVenue{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case "storyAreaTypeSuggestedReaction":
		// Decoding storyAreaTypeSuggestedReaction#f95f927c.
		v := StoryAreaTypeSuggestedReaction{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case "storyAreaTypeMessage":
		// Decoding storyAreaTypeMessage#bfef76b4.
		v := StoryAreaTypeMessage{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case "storyAreaTypeLink":
		// Decoding storyAreaTypeLink#f8626185.
		v := StoryAreaTypeLink{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case "storyAreaTypeWeather":
		// Decoding storyAreaTypeWeather#a6587dbe.
		v := StoryAreaTypeWeather{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	case "storyAreaTypeUpgradedGift":
		// Decoding storyAreaTypeUpgradedGift#2d50f987.
		v := StoryAreaTypeUpgradedGift{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode StoryAreaTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// StoryAreaType boxes the StoryAreaTypeClass providing a helper.
type StoryAreaTypeBox struct {
	StoryAreaType StoryAreaTypeClass
}

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

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

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

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