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

// BotsGetRequestedWebViewButtonRequest represents TL type `bots.getRequestedWebViewButton#bf25b7f3`.
//
// See https://core.telegram.org/method/bots.getRequestedWebViewButton for reference.
type BotsGetRequestedWebViewButtonRequest struct {
	// Bot field of BotsGetRequestedWebViewButtonRequest.
	Bot InputUserClass
	// WebappReqID field of BotsGetRequestedWebViewButtonRequest.
	WebappReqID string
}

// BotsGetRequestedWebViewButtonRequestTypeID is TL type id of BotsGetRequestedWebViewButtonRequest.
const BotsGetRequestedWebViewButtonRequestTypeID = 0xbf25b7f3

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

func (g *BotsGetRequestedWebViewButtonRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Bot == nil) {
		return false
	}
	if !(g.WebappReqID == "") {
		return false
	}

	return true
}

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

// FillFrom fills BotsGetRequestedWebViewButtonRequest from given interface.
func (g *BotsGetRequestedWebViewButtonRequest) FillFrom(from interface {
	GetBot() (value InputUserClass)
	GetWebappReqID() (value string)
}) {
	g.Bot = from.GetBot()
	g.WebappReqID = from.GetWebappReqID()
}

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

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

// TypeInfo returns info about TL type.
func (g *BotsGetRequestedWebViewButtonRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "bots.getRequestedWebViewButton",
		ID:   BotsGetRequestedWebViewButtonRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "WebappReqID",
			SchemaName: "webapp_req_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *BotsGetRequestedWebViewButtonRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode bots.getRequestedWebViewButton#bf25b7f3 as nil")
	}
	b.PutID(BotsGetRequestedWebViewButtonRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *BotsGetRequestedWebViewButtonRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode bots.getRequestedWebViewButton#bf25b7f3 as nil")
	}
	if g.Bot == nil {
		return fmt.Errorf("unable to encode bots.getRequestedWebViewButton#bf25b7f3: field bot is nil")
	}
	if err := g.Bot.Encode(b); err != nil {
		return fmt.Errorf("unable to encode bots.getRequestedWebViewButton#bf25b7f3: field bot: %w", err)
	}
	b.PutString(g.WebappReqID)
	return nil
}

// Decode implements bin.Decoder.
func (g *BotsGetRequestedWebViewButtonRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode bots.getRequestedWebViewButton#bf25b7f3 to nil")
	}
	if err := b.ConsumeID(BotsGetRequestedWebViewButtonRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode bots.getRequestedWebViewButton#bf25b7f3: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *BotsGetRequestedWebViewButtonRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode bots.getRequestedWebViewButton#bf25b7f3 to nil")
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode bots.getRequestedWebViewButton#bf25b7f3: field bot: %w", err)
		}
		g.Bot = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode bots.getRequestedWebViewButton#bf25b7f3: field webapp_req_id: %w", err)
		}
		g.WebappReqID = value
	}
	return nil
}

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

// GetWebappReqID returns value of WebappReqID field.
func (g *BotsGetRequestedWebViewButtonRequest) GetWebappReqID() (value string) {
	if g == nil {
		return
	}
	return g.WebappReqID
}

// BotsGetRequestedWebViewButton invokes method bots.getRequestedWebViewButton#bf25b7f3 returning error if any.
//
// See https://core.telegram.org/method/bots.getRequestedWebViewButton for reference.
func (c *Client) BotsGetRequestedWebViewButton(ctx context.Context, request *BotsGetRequestedWebViewButtonRequest) (KeyboardButtonClass, error) {
	var result KeyboardButtonBox

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