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

// MessagesEmojiGameOutcome represents TL type `messages.emojiGameOutcome#da2ad647`.
//
// See https://core.telegram.org/constructor/messages.emojiGameOutcome for reference.
type MessagesEmojiGameOutcome struct {
	// Seed field of MessagesEmojiGameOutcome.
	Seed []byte
	// StakeTonAmount field of MessagesEmojiGameOutcome.
	StakeTonAmount int64
	// TonAmount field of MessagesEmojiGameOutcome.
	TonAmount int64
}

// MessagesEmojiGameOutcomeTypeID is TL type id of MessagesEmojiGameOutcome.
const MessagesEmojiGameOutcomeTypeID = 0xda2ad647

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

func (e *MessagesEmojiGameOutcome) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Seed == nil) {
		return false
	}
	if !(e.StakeTonAmount == 0) {
		return false
	}
	if !(e.TonAmount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesEmojiGameOutcome from given interface.
func (e *MessagesEmojiGameOutcome) FillFrom(from interface {
	GetSeed() (value []byte)
	GetStakeTonAmount() (value int64)
	GetTonAmount() (value int64)
}) {
	e.Seed = from.GetSeed()
	e.StakeTonAmount = from.GetStakeTonAmount()
	e.TonAmount = from.GetTonAmount()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesEmojiGameOutcome) TypeName() string {
	return "messages.emojiGameOutcome"
}

// TypeInfo returns info about TL type.
func (e *MessagesEmojiGameOutcome) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.emojiGameOutcome",
		ID:   MessagesEmojiGameOutcomeTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Seed",
			SchemaName: "seed",
		},
		{
			Name:       "StakeTonAmount",
			SchemaName: "stake_ton_amount",
		},
		{
			Name:       "TonAmount",
			SchemaName: "ton_amount",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *MessagesEmojiGameOutcome) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.emojiGameOutcome#da2ad647 as nil")
	}
	b.PutID(MessagesEmojiGameOutcomeTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *MessagesEmojiGameOutcome) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.emojiGameOutcome#da2ad647 as nil")
	}
	b.PutBytes(e.Seed)
	b.PutLong(e.StakeTonAmount)
	b.PutLong(e.TonAmount)
	return nil
}

// Decode implements bin.Decoder.
func (e *MessagesEmojiGameOutcome) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.emojiGameOutcome#da2ad647 to nil")
	}
	if err := b.ConsumeID(MessagesEmojiGameOutcomeTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.emojiGameOutcome#da2ad647: %w", err)
	}
	return e.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (e *MessagesEmojiGameOutcome) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.emojiGameOutcome#da2ad647 to nil")
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode messages.emojiGameOutcome#da2ad647: field seed: %w", err)
		}
		e.Seed = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.emojiGameOutcome#da2ad647: field stake_ton_amount: %w", err)
		}
		e.StakeTonAmount = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.emojiGameOutcome#da2ad647: field ton_amount: %w", err)
		}
		e.TonAmount = value
	}
	return nil
}

// GetSeed returns value of Seed field.
func (e *MessagesEmojiGameOutcome) GetSeed() (value []byte) {
	if e == nil {
		return
	}
	return e.Seed
}

// GetStakeTonAmount returns value of StakeTonAmount field.
func (e *MessagesEmojiGameOutcome) GetStakeTonAmount() (value int64) {
	if e == nil {
		return
	}
	return e.StakeTonAmount
}

// GetTonAmount returns value of TonAmount field.
func (e *MessagesEmojiGameOutcome) GetTonAmount() (value int64) {
	if e == nil {
		return
	}
	return e.TonAmount
}
