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

// ChatStatisticsSupergroup represents TL type `chatStatisticsSupergroup#c67549ef`.
type ChatStatisticsSupergroup struct {
	// A period to which the statistics applies
	Period DateRange
	// Number of members in the chat
	MemberCount StatisticalValue
	// Number of messages sent to the chat
	MessageCount StatisticalValue
	// Number of users who viewed messages in the chat
	ViewerCount StatisticalValue
	// Number of users who sent messages to the chat
	SenderCount StatisticalValue
	// A graph containing number of members in the chat
	MemberCountGraph StatisticalGraphClass
	// A graph containing number of members joined and left the chat
	JoinGraph StatisticalGraphClass
	// A graph containing number of new member joins per source
	JoinBySourceGraph StatisticalGraphClass
	// A graph containing distribution of active users per language
	LanguageGraph StatisticalGraphClass
	// A graph containing distribution of sent messages by content type
	MessageContentGraph StatisticalGraphClass
	// A graph containing number of different actions in the chat
	ActionGraph StatisticalGraphClass
	// A graph containing distribution of message views per hour
	DayGraph StatisticalGraphClass
	// A graph containing distribution of message views per day of week
	WeekGraph StatisticalGraphClass
	// List of users sent most messages in the last week
	TopSenders []ChatStatisticsMessageSenderInfo
	// List of most active administrators in the last week
	TopAdministrators []ChatStatisticsAdministratorActionsInfo
	// List of most active inviters of new members in the last week
	TopInviters []ChatStatisticsInviterInfo
}

// ChatStatisticsSupergroupTypeID is TL type id of ChatStatisticsSupergroup.
const ChatStatisticsSupergroupTypeID = 0xc67549ef

// construct implements constructor of ChatStatisticsClass.
func (c ChatStatisticsSupergroup) construct() ChatStatisticsClass { return &c }

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

	_ ChatStatisticsClass = &ChatStatisticsSupergroup{}
)

func (c *ChatStatisticsSupergroup) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Period.Zero()) {
		return false
	}
	if !(c.MemberCount.Zero()) {
		return false
	}
	if !(c.MessageCount.Zero()) {
		return false
	}
	if !(c.ViewerCount.Zero()) {
		return false
	}
	if !(c.SenderCount.Zero()) {
		return false
	}
	if !(c.MemberCountGraph == nil) {
		return false
	}
	if !(c.JoinGraph == nil) {
		return false
	}
	if !(c.JoinBySourceGraph == nil) {
		return false
	}
	if !(c.LanguageGraph == nil) {
		return false
	}
	if !(c.MessageContentGraph == nil) {
		return false
	}
	if !(c.ActionGraph == nil) {
		return false
	}
	if !(c.DayGraph == nil) {
		return false
	}
	if !(c.WeekGraph == nil) {
		return false
	}
	if !(c.TopSenders == nil) {
		return false
	}
	if !(c.TopAdministrators == nil) {
		return false
	}
	if !(c.TopInviters == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ChatStatisticsSupergroup) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "chatStatisticsSupergroup",
		ID:   ChatStatisticsSupergroupTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Period",
			SchemaName: "period",
		},
		{
			Name:       "MemberCount",
			SchemaName: "member_count",
		},
		{
			Name:       "MessageCount",
			SchemaName: "message_count",
		},
		{
			Name:       "ViewerCount",
			SchemaName: "viewer_count",
		},
		{
			Name:       "SenderCount",
			SchemaName: "sender_count",
		},
		{
			Name:       "MemberCountGraph",
			SchemaName: "member_count_graph",
		},
		{
			Name:       "JoinGraph",
			SchemaName: "join_graph",
		},
		{
			Name:       "JoinBySourceGraph",
			SchemaName: "join_by_source_graph",
		},
		{
			Name:       "LanguageGraph",
			SchemaName: "language_graph",
		},
		{
			Name:       "MessageContentGraph",
			SchemaName: "message_content_graph",
		},
		{
			Name:       "ActionGraph",
			SchemaName: "action_graph",
		},
		{
			Name:       "DayGraph",
			SchemaName: "day_graph",
		},
		{
			Name:       "WeekGraph",
			SchemaName: "week_graph",
		},
		{
			Name:       "TopSenders",
			SchemaName: "top_senders",
		},
		{
			Name:       "TopAdministrators",
			SchemaName: "top_administrators",
		},
		{
			Name:       "TopInviters",
			SchemaName: "top_inviters",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ChatStatisticsSupergroup) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatStatisticsSupergroup#c67549ef as nil")
	}
	b.PutID(ChatStatisticsSupergroupTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ChatStatisticsSupergroup) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatStatisticsSupergroup#c67549ef as nil")
	}
	if err := c.Period.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field period: %w", err)
	}
	if err := c.MemberCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field member_count: %w", err)
	}
	if err := c.MessageCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field message_count: %w", err)
	}
	if err := c.ViewerCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field viewer_count: %w", err)
	}
	if err := c.SenderCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field sender_count: %w", err)
	}
	if c.MemberCountGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field member_count_graph is nil")
	}
	if err := c.MemberCountGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field member_count_graph: %w", err)
	}
	if c.JoinGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_graph is nil")
	}
	if err := c.JoinGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_graph: %w", err)
	}
	if c.JoinBySourceGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_by_source_graph is nil")
	}
	if err := c.JoinBySourceGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_by_source_graph: %w", err)
	}
	if c.LanguageGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field language_graph is nil")
	}
	if err := c.LanguageGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field language_graph: %w", err)
	}
	if c.MessageContentGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field message_content_graph is nil")
	}
	if err := c.MessageContentGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field message_content_graph: %w", err)
	}
	if c.ActionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field action_graph is nil")
	}
	if err := c.ActionGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field action_graph: %w", err)
	}
	if c.DayGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field day_graph is nil")
	}
	if err := c.DayGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field day_graph: %w", err)
	}
	if c.WeekGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field week_graph is nil")
	}
	if err := c.WeekGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field week_graph: %w", err)
	}
	b.PutInt(len(c.TopSenders))
	for idx, v := range c.TopSenders {
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare chatStatisticsSupergroup#c67549ef: field top_senders element with index %d: %w", idx, err)
		}
	}
	b.PutInt(len(c.TopAdministrators))
	for idx, v := range c.TopAdministrators {
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare chatStatisticsSupergroup#c67549ef: field top_administrators element with index %d: %w", idx, err)
		}
	}
	b.PutInt(len(c.TopInviters))
	for idx, v := range c.TopInviters {
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare chatStatisticsSupergroup#c67549ef: field top_inviters element with index %d: %w", idx, err)
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *ChatStatisticsSupergroup) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatStatisticsSupergroup#c67549ef to nil")
	}
	{
		if err := c.Period.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field period: %w", err)
		}
	}
	{
		if err := c.MemberCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field member_count: %w", err)
		}
	}
	{
		if err := c.MessageCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field message_count: %w", err)
		}
	}
	{
		if err := c.ViewerCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field viewer_count: %w", err)
		}
	}
	{
		if err := c.SenderCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field sender_count: %w", err)
		}
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field member_count_graph: %w", err)
		}
		c.MemberCountGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field join_graph: %w", err)
		}
		c.JoinGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field join_by_source_graph: %w", err)
		}
		c.JoinBySourceGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field language_graph: %w", err)
		}
		c.LanguageGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field message_content_graph: %w", err)
		}
		c.MessageContentGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field action_graph: %w", err)
		}
		c.ActionGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field day_graph: %w", err)
		}
		c.DayGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field week_graph: %w", err)
		}
		c.WeekGraph = value
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_senders: %w", err)
		}

		if headerLen > 0 {
			c.TopSenders = make([]ChatStatisticsMessageSenderInfo, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value ChatStatisticsMessageSenderInfo
			if err := value.DecodeBare(b); err != nil {
				return fmt.Errorf("unable to decode bare chatStatisticsSupergroup#c67549ef: field top_senders: %w", err)
			}
			c.TopSenders = append(c.TopSenders, value)
		}
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_administrators: %w", err)
		}

		if headerLen > 0 {
			c.TopAdministrators = make([]ChatStatisticsAdministratorActionsInfo, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value ChatStatisticsAdministratorActionsInfo
			if err := value.DecodeBare(b); err != nil {
				return fmt.Errorf("unable to decode bare chatStatisticsSupergroup#c67549ef: field top_administrators: %w", err)
			}
			c.TopAdministrators = append(c.TopAdministrators, value)
		}
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_inviters: %w", err)
		}

		if headerLen > 0 {
			c.TopInviters = make([]ChatStatisticsInviterInfo, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value ChatStatisticsInviterInfo
			if err := value.DecodeBare(b); err != nil {
				return fmt.Errorf("unable to decode bare chatStatisticsSupergroup#c67549ef: field top_inviters: %w", err)
			}
			c.TopInviters = append(c.TopInviters, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ChatStatisticsSupergroup) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode chatStatisticsSupergroup#c67549ef as nil")
	}
	b.ObjStart()
	b.PutID("chatStatisticsSupergroup")
	b.Comma()
	b.FieldStart("period")
	if err := c.Period.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field period: %w", err)
	}
	b.Comma()
	b.FieldStart("member_count")
	if err := c.MemberCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field member_count: %w", err)
	}
	b.Comma()
	b.FieldStart("message_count")
	if err := c.MessageCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field message_count: %w", err)
	}
	b.Comma()
	b.FieldStart("viewer_count")
	if err := c.ViewerCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field viewer_count: %w", err)
	}
	b.Comma()
	b.FieldStart("sender_count")
	if err := c.SenderCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field sender_count: %w", err)
	}
	b.Comma()
	b.FieldStart("member_count_graph")
	if c.MemberCountGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field member_count_graph is nil")
	}
	if err := c.MemberCountGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field member_count_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("join_graph")
	if c.JoinGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_graph is nil")
	}
	if err := c.JoinGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("join_by_source_graph")
	if c.JoinBySourceGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_by_source_graph is nil")
	}
	if err := c.JoinBySourceGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field join_by_source_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("language_graph")
	if c.LanguageGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field language_graph is nil")
	}
	if err := c.LanguageGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field language_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("message_content_graph")
	if c.MessageContentGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field message_content_graph is nil")
	}
	if err := c.MessageContentGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field message_content_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("action_graph")
	if c.ActionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field action_graph is nil")
	}
	if err := c.ActionGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field action_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("day_graph")
	if c.DayGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field day_graph is nil")
	}
	if err := c.DayGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field day_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("week_graph")
	if c.WeekGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field week_graph is nil")
	}
	if err := c.WeekGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field week_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("top_senders")
	b.ArrStart()
	for idx, v := range c.TopSenders {
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field top_senders element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.FieldStart("top_administrators")
	b.ArrStart()
	for idx, v := range c.TopAdministrators {
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field top_administrators element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.FieldStart("top_inviters")
	b.ArrStart()
	for idx, v := range c.TopInviters {
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode chatStatisticsSupergroup#c67549ef: field top_inviters element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("chatStatisticsSupergroup"); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: %w", err)
			}
		case "period":
			if err := c.Period.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field period: %w", err)
			}
		case "member_count":
			if err := c.MemberCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field member_count: %w", err)
			}
		case "message_count":
			if err := c.MessageCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field message_count: %w", err)
			}
		case "viewer_count":
			if err := c.ViewerCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field viewer_count: %w", err)
			}
		case "sender_count":
			if err := c.SenderCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field sender_count: %w", err)
			}
		case "member_count_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field member_count_graph: %w", err)
			}
			c.MemberCountGraph = value
		case "join_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field join_graph: %w", err)
			}
			c.JoinGraph = value
		case "join_by_source_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field join_by_source_graph: %w", err)
			}
			c.JoinBySourceGraph = value
		case "language_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field language_graph: %w", err)
			}
			c.LanguageGraph = value
		case "message_content_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field message_content_graph: %w", err)
			}
			c.MessageContentGraph = value
		case "action_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field action_graph: %w", err)
			}
			c.ActionGraph = value
		case "day_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field day_graph: %w", err)
			}
			c.DayGraph = value
		case "week_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field week_graph: %w", err)
			}
			c.WeekGraph = value
		case "top_senders":
			if err := b.Arr(func(b tdjson.Decoder) error {
				var value ChatStatisticsMessageSenderInfo
				if err := value.DecodeTDLibJSON(b); err != nil {
					return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_senders: %w", err)
				}
				c.TopSenders = append(c.TopSenders, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_senders: %w", err)
			}
		case "top_administrators":
			if err := b.Arr(func(b tdjson.Decoder) error {
				var value ChatStatisticsAdministratorActionsInfo
				if err := value.DecodeTDLibJSON(b); err != nil {
					return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_administrators: %w", err)
				}
				c.TopAdministrators = append(c.TopAdministrators, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_administrators: %w", err)
			}
		case "top_inviters":
			if err := b.Arr(func(b tdjson.Decoder) error {
				var value ChatStatisticsInviterInfo
				if err := value.DecodeTDLibJSON(b); err != nil {
					return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_inviters: %w", err)
				}
				c.TopInviters = append(c.TopInviters, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsSupergroup#c67549ef: field top_inviters: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPeriod returns value of Period field.
func (c *ChatStatisticsSupergroup) GetPeriod() (value DateRange) {
	if c == nil {
		return
	}
	return c.Period
}

// GetMemberCount returns value of MemberCount field.
func (c *ChatStatisticsSupergroup) GetMemberCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MemberCount
}

// GetMessageCount returns value of MessageCount field.
func (c *ChatStatisticsSupergroup) GetMessageCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MessageCount
}

// GetViewerCount returns value of ViewerCount field.
func (c *ChatStatisticsSupergroup) GetViewerCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.ViewerCount
}

// GetSenderCount returns value of SenderCount field.
func (c *ChatStatisticsSupergroup) GetSenderCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.SenderCount
}

// GetMemberCountGraph returns value of MemberCountGraph field.
func (c *ChatStatisticsSupergroup) GetMemberCountGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.MemberCountGraph
}

// GetJoinGraph returns value of JoinGraph field.
func (c *ChatStatisticsSupergroup) GetJoinGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.JoinGraph
}

// GetJoinBySourceGraph returns value of JoinBySourceGraph field.
func (c *ChatStatisticsSupergroup) GetJoinBySourceGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.JoinBySourceGraph
}

// GetLanguageGraph returns value of LanguageGraph field.
func (c *ChatStatisticsSupergroup) GetLanguageGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.LanguageGraph
}

// GetMessageContentGraph returns value of MessageContentGraph field.
func (c *ChatStatisticsSupergroup) GetMessageContentGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.MessageContentGraph
}

// GetActionGraph returns value of ActionGraph field.
func (c *ChatStatisticsSupergroup) GetActionGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.ActionGraph
}

// GetDayGraph returns value of DayGraph field.
func (c *ChatStatisticsSupergroup) GetDayGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.DayGraph
}

// GetWeekGraph returns value of WeekGraph field.
func (c *ChatStatisticsSupergroup) GetWeekGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.WeekGraph
}

// GetTopSenders returns value of TopSenders field.
func (c *ChatStatisticsSupergroup) GetTopSenders() (value []ChatStatisticsMessageSenderInfo) {
	if c == nil {
		return
	}
	return c.TopSenders
}

// GetTopAdministrators returns value of TopAdministrators field.
func (c *ChatStatisticsSupergroup) GetTopAdministrators() (value []ChatStatisticsAdministratorActionsInfo) {
	if c == nil {
		return
	}
	return c.TopAdministrators
}

// GetTopInviters returns value of TopInviters field.
func (c *ChatStatisticsSupergroup) GetTopInviters() (value []ChatStatisticsInviterInfo) {
	if c == nil {
		return
	}
	return c.TopInviters
}

// ChatStatisticsChannel represents TL type `chatStatisticsChannel#b8e95b4`.
type ChatStatisticsChannel struct {
	// A period to which the statistics applies
	Period DateRange
	// Number of members in the chat
	MemberCount StatisticalValue
	// Mean number of times the recently sent messages were viewed
	MeanMessageViewCount StatisticalValue
	// Mean number of times the recently sent messages were shared
	MeanMessageShareCount StatisticalValue
	// Mean number of times reactions were added to the recently sent messages
	MeanMessageReactionCount StatisticalValue
	// Mean number of times the recently posted stories were viewed
	MeanStoryViewCount StatisticalValue
	// Mean number of times the recently posted stories were shared
	MeanStoryShareCount StatisticalValue
	// Mean number of times reactions were added to the recently posted stories
	MeanStoryReactionCount StatisticalValue
	// A percentage of users with enabled notifications for the chat; 0-100
	EnabledNotificationsPercentage float64
	// A graph containing number of members in the chat
	MemberCountGraph StatisticalGraphClass
	// A graph containing number of members joined and left the chat
	JoinGraph StatisticalGraphClass
	// A graph containing number of members muted and unmuted the chat
	MuteGraph StatisticalGraphClass
	// A graph containing number of message views in a given hour in the last two weeks
	ViewCountByHourGraph StatisticalGraphClass
	// A graph containing number of message views per source
	ViewCountBySourceGraph StatisticalGraphClass
	// A graph containing number of new member joins per source
	JoinBySourceGraph StatisticalGraphClass
	// A graph containing number of users viewed chat messages per language
	LanguageGraph StatisticalGraphClass
	// A graph containing number of chat message views and shares
	MessageInteractionGraph StatisticalGraphClass
	// A graph containing number of reactions on messages
	MessageReactionGraph StatisticalGraphClass
	// A graph containing number of story views and shares
	StoryInteractionGraph StatisticalGraphClass
	// A graph containing number of reactions on stories
	StoryReactionGraph StatisticalGraphClass
	// A graph containing number of views of associated with the chat instant views
	InstantViewInteractionGraph StatisticalGraphClass
	// Detailed statistics about number of views and shares of recently sent messages and
	// posted stories
	RecentInteractions []ChatStatisticsInteractionInfo
}

// ChatStatisticsChannelTypeID is TL type id of ChatStatisticsChannel.
const ChatStatisticsChannelTypeID = 0xb8e95b4

// construct implements constructor of ChatStatisticsClass.
func (c ChatStatisticsChannel) construct() ChatStatisticsClass { return &c }

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

	_ ChatStatisticsClass = &ChatStatisticsChannel{}
)

func (c *ChatStatisticsChannel) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Period.Zero()) {
		return false
	}
	if !(c.MemberCount.Zero()) {
		return false
	}
	if !(c.MeanMessageViewCount.Zero()) {
		return false
	}
	if !(c.MeanMessageShareCount.Zero()) {
		return false
	}
	if !(c.MeanMessageReactionCount.Zero()) {
		return false
	}
	if !(c.MeanStoryViewCount.Zero()) {
		return false
	}
	if !(c.MeanStoryShareCount.Zero()) {
		return false
	}
	if !(c.MeanStoryReactionCount.Zero()) {
		return false
	}
	if !(c.EnabledNotificationsPercentage == 0) {
		return false
	}
	if !(c.MemberCountGraph == nil) {
		return false
	}
	if !(c.JoinGraph == nil) {
		return false
	}
	if !(c.MuteGraph == nil) {
		return false
	}
	if !(c.ViewCountByHourGraph == nil) {
		return false
	}
	if !(c.ViewCountBySourceGraph == nil) {
		return false
	}
	if !(c.JoinBySourceGraph == nil) {
		return false
	}
	if !(c.LanguageGraph == nil) {
		return false
	}
	if !(c.MessageInteractionGraph == nil) {
		return false
	}
	if !(c.MessageReactionGraph == nil) {
		return false
	}
	if !(c.StoryInteractionGraph == nil) {
		return false
	}
	if !(c.StoryReactionGraph == nil) {
		return false
	}
	if !(c.InstantViewInteractionGraph == nil) {
		return false
	}
	if !(c.RecentInteractions == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *ChatStatisticsChannel) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "chatStatisticsChannel",
		ID:   ChatStatisticsChannelTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Period",
			SchemaName: "period",
		},
		{
			Name:       "MemberCount",
			SchemaName: "member_count",
		},
		{
			Name:       "MeanMessageViewCount",
			SchemaName: "mean_message_view_count",
		},
		{
			Name:       "MeanMessageShareCount",
			SchemaName: "mean_message_share_count",
		},
		{
			Name:       "MeanMessageReactionCount",
			SchemaName: "mean_message_reaction_count",
		},
		{
			Name:       "MeanStoryViewCount",
			SchemaName: "mean_story_view_count",
		},
		{
			Name:       "MeanStoryShareCount",
			SchemaName: "mean_story_share_count",
		},
		{
			Name:       "MeanStoryReactionCount",
			SchemaName: "mean_story_reaction_count",
		},
		{
			Name:       "EnabledNotificationsPercentage",
			SchemaName: "enabled_notifications_percentage",
		},
		{
			Name:       "MemberCountGraph",
			SchemaName: "member_count_graph",
		},
		{
			Name:       "JoinGraph",
			SchemaName: "join_graph",
		},
		{
			Name:       "MuteGraph",
			SchemaName: "mute_graph",
		},
		{
			Name:       "ViewCountByHourGraph",
			SchemaName: "view_count_by_hour_graph",
		},
		{
			Name:       "ViewCountBySourceGraph",
			SchemaName: "view_count_by_source_graph",
		},
		{
			Name:       "JoinBySourceGraph",
			SchemaName: "join_by_source_graph",
		},
		{
			Name:       "LanguageGraph",
			SchemaName: "language_graph",
		},
		{
			Name:       "MessageInteractionGraph",
			SchemaName: "message_interaction_graph",
		},
		{
			Name:       "MessageReactionGraph",
			SchemaName: "message_reaction_graph",
		},
		{
			Name:       "StoryInteractionGraph",
			SchemaName: "story_interaction_graph",
		},
		{
			Name:       "StoryReactionGraph",
			SchemaName: "story_reaction_graph",
		},
		{
			Name:       "InstantViewInteractionGraph",
			SchemaName: "instant_view_interaction_graph",
		},
		{
			Name:       "RecentInteractions",
			SchemaName: "recent_interactions",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ChatStatisticsChannel) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatStatisticsChannel#b8e95b4 as nil")
	}
	b.PutID(ChatStatisticsChannelTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ChatStatisticsChannel) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatStatisticsChannel#b8e95b4 as nil")
	}
	if err := c.Period.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field period: %w", err)
	}
	if err := c.MemberCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field member_count: %w", err)
	}
	if err := c.MeanMessageViewCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_message_view_count: %w", err)
	}
	if err := c.MeanMessageShareCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_message_share_count: %w", err)
	}
	if err := c.MeanMessageReactionCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_message_reaction_count: %w", err)
	}
	if err := c.MeanStoryViewCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_story_view_count: %w", err)
	}
	if err := c.MeanStoryShareCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_story_share_count: %w", err)
	}
	if err := c.MeanStoryReactionCount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_story_reaction_count: %w", err)
	}
	b.PutDouble(c.EnabledNotificationsPercentage)
	if c.MemberCountGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field member_count_graph is nil")
	}
	if err := c.MemberCountGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field member_count_graph: %w", err)
	}
	if c.JoinGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_graph is nil")
	}
	if err := c.JoinGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_graph: %w", err)
	}
	if c.MuteGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mute_graph is nil")
	}
	if err := c.MuteGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mute_graph: %w", err)
	}
	if c.ViewCountByHourGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_hour_graph is nil")
	}
	if err := c.ViewCountByHourGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_hour_graph: %w", err)
	}
	if c.ViewCountBySourceGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_source_graph is nil")
	}
	if err := c.ViewCountBySourceGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_source_graph: %w", err)
	}
	if c.JoinBySourceGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_by_source_graph is nil")
	}
	if err := c.JoinBySourceGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_by_source_graph: %w", err)
	}
	if c.LanguageGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field language_graph is nil")
	}
	if err := c.LanguageGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field language_graph: %w", err)
	}
	if c.MessageInteractionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_interaction_graph is nil")
	}
	if err := c.MessageInteractionGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_interaction_graph: %w", err)
	}
	if c.MessageReactionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_reaction_graph is nil")
	}
	if err := c.MessageReactionGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_reaction_graph: %w", err)
	}
	if c.StoryInteractionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_interaction_graph is nil")
	}
	if err := c.StoryInteractionGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_interaction_graph: %w", err)
	}
	if c.StoryReactionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_reaction_graph is nil")
	}
	if err := c.StoryReactionGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_reaction_graph: %w", err)
	}
	if c.InstantViewInteractionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field instant_view_interaction_graph is nil")
	}
	if err := c.InstantViewInteractionGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field instant_view_interaction_graph: %w", err)
	}
	b.PutInt(len(c.RecentInteractions))
	for idx, v := range c.RecentInteractions {
		if err := v.EncodeBare(b); err != nil {
			return fmt.Errorf("unable to encode bare chatStatisticsChannel#b8e95b4: field recent_interactions element with index %d: %w", idx, err)
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *ChatStatisticsChannel) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatStatisticsChannel#b8e95b4 to nil")
	}
	{
		if err := c.Period.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field period: %w", err)
		}
	}
	{
		if err := c.MemberCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field member_count: %w", err)
		}
	}
	{
		if err := c.MeanMessageViewCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_message_view_count: %w", err)
		}
	}
	{
		if err := c.MeanMessageShareCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_message_share_count: %w", err)
		}
	}
	{
		if err := c.MeanMessageReactionCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_message_reaction_count: %w", err)
		}
	}
	{
		if err := c.MeanStoryViewCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_story_view_count: %w", err)
		}
	}
	{
		if err := c.MeanStoryShareCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_story_share_count: %w", err)
		}
	}
	{
		if err := c.MeanStoryReactionCount.Decode(b); err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_story_reaction_count: %w", err)
		}
	}
	{
		value, err := b.Double()
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field enabled_notifications_percentage: %w", err)
		}
		c.EnabledNotificationsPercentage = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field member_count_graph: %w", err)
		}
		c.MemberCountGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field join_graph: %w", err)
		}
		c.JoinGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mute_graph: %w", err)
		}
		c.MuteGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field view_count_by_hour_graph: %w", err)
		}
		c.ViewCountByHourGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field view_count_by_source_graph: %w", err)
		}
		c.ViewCountBySourceGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field join_by_source_graph: %w", err)
		}
		c.JoinBySourceGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field language_graph: %w", err)
		}
		c.LanguageGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field message_interaction_graph: %w", err)
		}
		c.MessageInteractionGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field message_reaction_graph: %w", err)
		}
		c.MessageReactionGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field story_interaction_graph: %w", err)
		}
		c.StoryInteractionGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field story_reaction_graph: %w", err)
		}
		c.StoryReactionGraph = value
	}
	{
		value, err := DecodeStatisticalGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field instant_view_interaction_graph: %w", err)
		}
		c.InstantViewInteractionGraph = value
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field recent_interactions: %w", err)
		}

		if headerLen > 0 {
			c.RecentInteractions = make([]ChatStatisticsInteractionInfo, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value ChatStatisticsInteractionInfo
			if err := value.DecodeBare(b); err != nil {
				return fmt.Errorf("unable to decode bare chatStatisticsChannel#b8e95b4: field recent_interactions: %w", err)
			}
			c.RecentInteractions = append(c.RecentInteractions, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ChatStatisticsChannel) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode chatStatisticsChannel#b8e95b4 as nil")
	}
	b.ObjStart()
	b.PutID("chatStatisticsChannel")
	b.Comma()
	b.FieldStart("period")
	if err := c.Period.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field period: %w", err)
	}
	b.Comma()
	b.FieldStart("member_count")
	if err := c.MemberCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field member_count: %w", err)
	}
	b.Comma()
	b.FieldStart("mean_message_view_count")
	if err := c.MeanMessageViewCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_message_view_count: %w", err)
	}
	b.Comma()
	b.FieldStart("mean_message_share_count")
	if err := c.MeanMessageShareCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_message_share_count: %w", err)
	}
	b.Comma()
	b.FieldStart("mean_message_reaction_count")
	if err := c.MeanMessageReactionCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_message_reaction_count: %w", err)
	}
	b.Comma()
	b.FieldStart("mean_story_view_count")
	if err := c.MeanStoryViewCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_story_view_count: %w", err)
	}
	b.Comma()
	b.FieldStart("mean_story_share_count")
	if err := c.MeanStoryShareCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_story_share_count: %w", err)
	}
	b.Comma()
	b.FieldStart("mean_story_reaction_count")
	if err := c.MeanStoryReactionCount.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mean_story_reaction_count: %w", err)
	}
	b.Comma()
	b.FieldStart("enabled_notifications_percentage")
	b.PutDouble(c.EnabledNotificationsPercentage)
	b.Comma()
	b.FieldStart("member_count_graph")
	if c.MemberCountGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field member_count_graph is nil")
	}
	if err := c.MemberCountGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field member_count_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("join_graph")
	if c.JoinGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_graph is nil")
	}
	if err := c.JoinGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("mute_graph")
	if c.MuteGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mute_graph is nil")
	}
	if err := c.MuteGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field mute_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("view_count_by_hour_graph")
	if c.ViewCountByHourGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_hour_graph is nil")
	}
	if err := c.ViewCountByHourGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_hour_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("view_count_by_source_graph")
	if c.ViewCountBySourceGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_source_graph is nil")
	}
	if err := c.ViewCountBySourceGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field view_count_by_source_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("join_by_source_graph")
	if c.JoinBySourceGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_by_source_graph is nil")
	}
	if err := c.JoinBySourceGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field join_by_source_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("language_graph")
	if c.LanguageGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field language_graph is nil")
	}
	if err := c.LanguageGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field language_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("message_interaction_graph")
	if c.MessageInteractionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_interaction_graph is nil")
	}
	if err := c.MessageInteractionGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_interaction_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("message_reaction_graph")
	if c.MessageReactionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_reaction_graph is nil")
	}
	if err := c.MessageReactionGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field message_reaction_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("story_interaction_graph")
	if c.StoryInteractionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_interaction_graph is nil")
	}
	if err := c.StoryInteractionGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_interaction_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("story_reaction_graph")
	if c.StoryReactionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_reaction_graph is nil")
	}
	if err := c.StoryReactionGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field story_reaction_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("instant_view_interaction_graph")
	if c.InstantViewInteractionGraph == nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field instant_view_interaction_graph is nil")
	}
	if err := c.InstantViewInteractionGraph.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field instant_view_interaction_graph: %w", err)
	}
	b.Comma()
	b.FieldStart("recent_interactions")
	b.ArrStart()
	for idx, v := range c.RecentInteractions {
		if err := v.EncodeTDLibJSON(b); err != nil {
			return fmt.Errorf("unable to encode chatStatisticsChannel#b8e95b4: field recent_interactions element with index %d: %w", idx, err)
		}
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("chatStatisticsChannel"); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: %w", err)
			}
		case "period":
			if err := c.Period.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field period: %w", err)
			}
		case "member_count":
			if err := c.MemberCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field member_count: %w", err)
			}
		case "mean_message_view_count":
			if err := c.MeanMessageViewCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_message_view_count: %w", err)
			}
		case "mean_message_share_count":
			if err := c.MeanMessageShareCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_message_share_count: %w", err)
			}
		case "mean_message_reaction_count":
			if err := c.MeanMessageReactionCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_message_reaction_count: %w", err)
			}
		case "mean_story_view_count":
			if err := c.MeanStoryViewCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_story_view_count: %w", err)
			}
		case "mean_story_share_count":
			if err := c.MeanStoryShareCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_story_share_count: %w", err)
			}
		case "mean_story_reaction_count":
			if err := c.MeanStoryReactionCount.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mean_story_reaction_count: %w", err)
			}
		case "enabled_notifications_percentage":
			value, err := b.Double()
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field enabled_notifications_percentage: %w", err)
			}
			c.EnabledNotificationsPercentage = value
		case "member_count_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field member_count_graph: %w", err)
			}
			c.MemberCountGraph = value
		case "join_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field join_graph: %w", err)
			}
			c.JoinGraph = value
		case "mute_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field mute_graph: %w", err)
			}
			c.MuteGraph = value
		case "view_count_by_hour_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field view_count_by_hour_graph: %w", err)
			}
			c.ViewCountByHourGraph = value
		case "view_count_by_source_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field view_count_by_source_graph: %w", err)
			}
			c.ViewCountBySourceGraph = value
		case "join_by_source_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field join_by_source_graph: %w", err)
			}
			c.JoinBySourceGraph = value
		case "language_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field language_graph: %w", err)
			}
			c.LanguageGraph = value
		case "message_interaction_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field message_interaction_graph: %w", err)
			}
			c.MessageInteractionGraph = value
		case "message_reaction_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field message_reaction_graph: %w", err)
			}
			c.MessageReactionGraph = value
		case "story_interaction_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field story_interaction_graph: %w", err)
			}
			c.StoryInteractionGraph = value
		case "story_reaction_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field story_reaction_graph: %w", err)
			}
			c.StoryReactionGraph = value
		case "instant_view_interaction_graph":
			value, err := DecodeTDLibJSONStatisticalGraph(b)
			if err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field instant_view_interaction_graph: %w", err)
			}
			c.InstantViewInteractionGraph = value
		case "recent_interactions":
			if err := b.Arr(func(b tdjson.Decoder) error {
				var value ChatStatisticsInteractionInfo
				if err := value.DecodeTDLibJSON(b); err != nil {
					return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field recent_interactions: %w", err)
				}
				c.RecentInteractions = append(c.RecentInteractions, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode chatStatisticsChannel#b8e95b4: field recent_interactions: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetPeriod returns value of Period field.
func (c *ChatStatisticsChannel) GetPeriod() (value DateRange) {
	if c == nil {
		return
	}
	return c.Period
}

// GetMemberCount returns value of MemberCount field.
func (c *ChatStatisticsChannel) GetMemberCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MemberCount
}

// GetMeanMessageViewCount returns value of MeanMessageViewCount field.
func (c *ChatStatisticsChannel) GetMeanMessageViewCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MeanMessageViewCount
}

// GetMeanMessageShareCount returns value of MeanMessageShareCount field.
func (c *ChatStatisticsChannel) GetMeanMessageShareCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MeanMessageShareCount
}

// GetMeanMessageReactionCount returns value of MeanMessageReactionCount field.
func (c *ChatStatisticsChannel) GetMeanMessageReactionCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MeanMessageReactionCount
}

// GetMeanStoryViewCount returns value of MeanStoryViewCount field.
func (c *ChatStatisticsChannel) GetMeanStoryViewCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MeanStoryViewCount
}

// GetMeanStoryShareCount returns value of MeanStoryShareCount field.
func (c *ChatStatisticsChannel) GetMeanStoryShareCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MeanStoryShareCount
}

// GetMeanStoryReactionCount returns value of MeanStoryReactionCount field.
func (c *ChatStatisticsChannel) GetMeanStoryReactionCount() (value StatisticalValue) {
	if c == nil {
		return
	}
	return c.MeanStoryReactionCount
}

// GetEnabledNotificationsPercentage returns value of EnabledNotificationsPercentage field.
func (c *ChatStatisticsChannel) GetEnabledNotificationsPercentage() (value float64) {
	if c == nil {
		return
	}
	return c.EnabledNotificationsPercentage
}

// GetMemberCountGraph returns value of MemberCountGraph field.
func (c *ChatStatisticsChannel) GetMemberCountGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.MemberCountGraph
}

// GetJoinGraph returns value of JoinGraph field.
func (c *ChatStatisticsChannel) GetJoinGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.JoinGraph
}

// GetMuteGraph returns value of MuteGraph field.
func (c *ChatStatisticsChannel) GetMuteGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.MuteGraph
}

// GetViewCountByHourGraph returns value of ViewCountByHourGraph field.
func (c *ChatStatisticsChannel) GetViewCountByHourGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.ViewCountByHourGraph
}

// GetViewCountBySourceGraph returns value of ViewCountBySourceGraph field.
func (c *ChatStatisticsChannel) GetViewCountBySourceGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.ViewCountBySourceGraph
}

// GetJoinBySourceGraph returns value of JoinBySourceGraph field.
func (c *ChatStatisticsChannel) GetJoinBySourceGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.JoinBySourceGraph
}

// GetLanguageGraph returns value of LanguageGraph field.
func (c *ChatStatisticsChannel) GetLanguageGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.LanguageGraph
}

// GetMessageInteractionGraph returns value of MessageInteractionGraph field.
func (c *ChatStatisticsChannel) GetMessageInteractionGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.MessageInteractionGraph
}

// GetMessageReactionGraph returns value of MessageReactionGraph field.
func (c *ChatStatisticsChannel) GetMessageReactionGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.MessageReactionGraph
}

// GetStoryInteractionGraph returns value of StoryInteractionGraph field.
func (c *ChatStatisticsChannel) GetStoryInteractionGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.StoryInteractionGraph
}

// GetStoryReactionGraph returns value of StoryReactionGraph field.
func (c *ChatStatisticsChannel) GetStoryReactionGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.StoryReactionGraph
}

// GetInstantViewInteractionGraph returns value of InstantViewInteractionGraph field.
func (c *ChatStatisticsChannel) GetInstantViewInteractionGraph() (value StatisticalGraphClass) {
	if c == nil {
		return
	}
	return c.InstantViewInteractionGraph
}

// GetRecentInteractions returns value of RecentInteractions field.
func (c *ChatStatisticsChannel) GetRecentInteractions() (value []ChatStatisticsInteractionInfo) {
	if c == nil {
		return
	}
	return c.RecentInteractions
}

// ChatStatisticsClassName is schema name of ChatStatisticsClass.
const ChatStatisticsClassName = "ChatStatistics"

// ChatStatisticsClass represents ChatStatistics generic type.
//
// Example:
//
//	g, err := tdapi.DecodeChatStatistics(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.ChatStatisticsSupergroup: // chatStatisticsSupergroup#c67549ef
//	case *tdapi.ChatStatisticsChannel: // chatStatisticsChannel#b8e95b4
//	default: panic(v)
//	}
type ChatStatisticsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ChatStatisticsClass

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

	// A period to which the statistics applies
	GetPeriod() (value DateRange)
	// Number of members in the chat
	GetMemberCount() (value StatisticalValue)
	// A graph containing number of members in the chat
	GetMemberCountGraph() (value StatisticalGraphClass)
	// A graph containing number of members joined and left the chat
	GetJoinGraph() (value StatisticalGraphClass)
	// A graph containing number of new member joins per source
	GetJoinBySourceGraph() (value StatisticalGraphClass)
	// A graph containing distribution of active users per language
	GetLanguageGraph() (value StatisticalGraphClass)
}

// DecodeChatStatistics implements binary de-serialization for ChatStatisticsClass.
func DecodeChatStatistics(buf *bin.Buffer) (ChatStatisticsClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case ChatStatisticsSupergroupTypeID:
		// Decoding chatStatisticsSupergroup#c67549ef.
		v := ChatStatisticsSupergroup{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatStatisticsClass: %w", err)
		}
		return &v, nil
	case ChatStatisticsChannelTypeID:
		// Decoding chatStatisticsChannel#b8e95b4.
		v := ChatStatisticsChannel{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatStatisticsClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatStatisticsClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONChatStatistics implements binary de-serialization for ChatStatisticsClass.
func DecodeTDLibJSONChatStatistics(buf tdjson.Decoder) (ChatStatisticsClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "chatStatisticsSupergroup":
		// Decoding chatStatisticsSupergroup#c67549ef.
		v := ChatStatisticsSupergroup{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatStatisticsClass: %w", err)
		}
		return &v, nil
	case "chatStatisticsChannel":
		// Decoding chatStatisticsChannel#b8e95b4.
		v := ChatStatisticsChannel{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ChatStatisticsClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatStatisticsClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// ChatStatistics boxes the ChatStatisticsClass providing a helper.
type ChatStatisticsBox struct {
	ChatStatistics ChatStatisticsClass
}

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

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

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

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