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

// BotsExportedBotToken represents TL type `bots.exportedBotToken#3c60b621`.
//
// See https://core.telegram.org/constructor/bots.exportedBotToken for reference.
type BotsExportedBotToken struct {
	// Token field of BotsExportedBotToken.
	Token string
}

// BotsExportedBotTokenTypeID is TL type id of BotsExportedBotToken.
const BotsExportedBotTokenTypeID = 0x3c60b621

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

func (e *BotsExportedBotToken) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Token == "") {
		return false
	}

	return true
}

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

// FillFrom fills BotsExportedBotToken from given interface.
func (e *BotsExportedBotToken) FillFrom(from interface {
	GetToken() (value string)
}) {
	e.Token = from.GetToken()
}

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

// TypeName returns name of type in TL schema.
func (*BotsExportedBotToken) TypeName() string {
	return "bots.exportedBotToken"
}

// TypeInfo returns info about TL type.
func (e *BotsExportedBotToken) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "bots.exportedBotToken",
		ID:   BotsExportedBotTokenTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Token",
			SchemaName: "token",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *BotsExportedBotToken) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode bots.exportedBotToken#3c60b621 as nil")
	}
	b.PutID(BotsExportedBotTokenTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *BotsExportedBotToken) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode bots.exportedBotToken#3c60b621 as nil")
	}
	b.PutString(e.Token)
	return nil
}

// Decode implements bin.Decoder.
func (e *BotsExportedBotToken) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode bots.exportedBotToken#3c60b621 to nil")
	}
	if err := b.ConsumeID(BotsExportedBotTokenTypeID); err != nil {
		return fmt.Errorf("unable to decode bots.exportedBotToken#3c60b621: %w", err)
	}
	return e.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (e *BotsExportedBotToken) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode bots.exportedBotToken#3c60b621 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode bots.exportedBotToken#3c60b621: field token: %w", err)
		}
		e.Token = value
	}
	return nil
}

// GetToken returns value of Token field.
func (e *BotsExportedBotToken) GetToken() (value string) {
	if e == nil {
		return
	}
	return e.Token
}
