// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// StatsPollStats represents TL type `stats.pollStats#2999beed`.
//
// See https://core.telegram.org/constructor/stats.pollStats for reference.
type StatsPollStats struct {
	// VotesGraph field of StatsPollStats.
	VotesGraph StatsGraphClass
}

// StatsPollStatsTypeID is TL type id of StatsPollStats.
const StatsPollStatsTypeID = 0x2999beed

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

func (p *StatsPollStats) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.VotesGraph == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StatsPollStats from given interface.
func (p *StatsPollStats) FillFrom(from interface {
	GetVotesGraph() (value StatsGraphClass)
}) {
	p.VotesGraph = from.GetVotesGraph()
}

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

// TypeName returns name of type in TL schema.
func (*StatsPollStats) TypeName() string {
	return "stats.pollStats"
}

// TypeInfo returns info about TL type.
func (p *StatsPollStats) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "stats.pollStats",
		ID:   StatsPollStatsTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "VotesGraph",
			SchemaName: "votes_graph",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *StatsPollStats) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode stats.pollStats#2999beed as nil")
	}
	b.PutID(StatsPollStatsTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *StatsPollStats) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode stats.pollStats#2999beed as nil")
	}
	if p.VotesGraph == nil {
		return fmt.Errorf("unable to encode stats.pollStats#2999beed: field votes_graph is nil")
	}
	if err := p.VotesGraph.Encode(b); err != nil {
		return fmt.Errorf("unable to encode stats.pollStats#2999beed: field votes_graph: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *StatsPollStats) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode stats.pollStats#2999beed to nil")
	}
	if err := b.ConsumeID(StatsPollStatsTypeID); err != nil {
		return fmt.Errorf("unable to decode stats.pollStats#2999beed: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *StatsPollStats) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode stats.pollStats#2999beed to nil")
	}
	{
		value, err := DecodeStatsGraph(b)
		if err != nil {
			return fmt.Errorf("unable to decode stats.pollStats#2999beed: field votes_graph: %w", err)
		}
		p.VotesGraph = value
	}
	return nil
}

// GetVotesGraph returns value of VotesGraph field.
func (p *StatsPollStats) GetVotesGraph() (value StatsGraphClass) {
	if p == nil {
		return
	}
	return p.VotesGraph
}
