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

// BotsExportBotTokenRequest represents TL type `bots.exportBotToken#bd0d99eb`.
//
// See https://core.telegram.org/method/bots.exportBotToken for reference.
type BotsExportBotTokenRequest struct {
	// Bot field of BotsExportBotTokenRequest.
	Bot InputUserClass
	// Revoke field of BotsExportBotTokenRequest.
	Revoke bool
}

// BotsExportBotTokenRequestTypeID is TL type id of BotsExportBotTokenRequest.
const BotsExportBotTokenRequestTypeID = 0xbd0d99eb

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

func (e *BotsExportBotTokenRequest) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Bot == nil) {
		return false
	}
	if !(e.Revoke == false) {
		return false
	}

	return true
}

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

// FillFrom fills BotsExportBotTokenRequest from given interface.
func (e *BotsExportBotTokenRequest) FillFrom(from interface {
	GetBot() (value InputUserClass)
	GetRevoke() (value bool)
}) {
	e.Bot = from.GetBot()
	e.Revoke = from.GetRevoke()
}

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

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

// TypeInfo returns info about TL type.
func (e *BotsExportBotTokenRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "bots.exportBotToken",
		ID:   BotsExportBotTokenRequestTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "Revoke",
			SchemaName: "revoke",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *BotsExportBotTokenRequest) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode bots.exportBotToken#bd0d99eb as nil")
	}
	b.PutID(BotsExportBotTokenRequestTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *BotsExportBotTokenRequest) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode bots.exportBotToken#bd0d99eb as nil")
	}
	if e.Bot == nil {
		return fmt.Errorf("unable to encode bots.exportBotToken#bd0d99eb: field bot is nil")
	}
	if err := e.Bot.Encode(b); err != nil {
		return fmt.Errorf("unable to encode bots.exportBotToken#bd0d99eb: field bot: %w", err)
	}
	b.PutBool(e.Revoke)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (e *BotsExportBotTokenRequest) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode bots.exportBotToken#bd0d99eb to nil")
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode bots.exportBotToken#bd0d99eb: field bot: %w", err)
		}
		e.Bot = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode bots.exportBotToken#bd0d99eb: field revoke: %w", err)
		}
		e.Revoke = value
	}
	return nil
}

// GetBot returns value of Bot field.
func (e *BotsExportBotTokenRequest) GetBot() (value InputUserClass) {
	if e == nil {
		return
	}
	return e.Bot
}

// GetRevoke returns value of Revoke field.
func (e *BotsExportBotTokenRequest) GetRevoke() (value bool) {
	if e == nil {
		return
	}
	return e.Revoke
}

// BotsExportBotToken invokes method bots.exportBotToken#bd0d99eb returning error if any.
//
// See https://core.telegram.org/method/bots.exportBotToken for reference.
func (c *Client) BotsExportBotToken(ctx context.Context, request *BotsExportBotTokenRequest) (*BotsExportedBotToken, error) {
	var result BotsExportedBotToken

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return &result, nil
}
