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

// MessagesSetBotGuestChatResultRequest represents TL type `messages.setBotGuestChatResult#52b08db`.
//
// See https://core.telegram.org/method/messages.setBotGuestChatResult for reference.
type MessagesSetBotGuestChatResultRequest struct {
	// QueryID field of MessagesSetBotGuestChatResultRequest.
	QueryID int64
	// Result field of MessagesSetBotGuestChatResultRequest.
	Result InputBotInlineResultClass
}

// MessagesSetBotGuestChatResultRequestTypeID is TL type id of MessagesSetBotGuestChatResultRequest.
const MessagesSetBotGuestChatResultRequestTypeID = 0x52b08db

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

func (s *MessagesSetBotGuestChatResultRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.QueryID == 0) {
		return false
	}
	if !(s.Result == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSetBotGuestChatResultRequest from given interface.
func (s *MessagesSetBotGuestChatResultRequest) FillFrom(from interface {
	GetQueryID() (value int64)
	GetResult() (value InputBotInlineResultClass)
}) {
	s.QueryID = from.GetQueryID()
	s.Result = from.GetResult()
}

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

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

// TypeInfo returns info about TL type.
func (s *MessagesSetBotGuestChatResultRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.setBotGuestChatResult",
		ID:   MessagesSetBotGuestChatResultRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "QueryID",
			SchemaName: "query_id",
		},
		{
			Name:       "Result",
			SchemaName: "result",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesSetBotGuestChatResultRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.setBotGuestChatResult#52b08db as nil")
	}
	b.PutID(MessagesSetBotGuestChatResultRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesSetBotGuestChatResultRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.setBotGuestChatResult#52b08db as nil")
	}
	b.PutLong(s.QueryID)
	if s.Result == nil {
		return fmt.Errorf("unable to encode messages.setBotGuestChatResult#52b08db: field result is nil")
	}
	if err := s.Result.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.setBotGuestChatResult#52b08db: field result: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *MessagesSetBotGuestChatResultRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.setBotGuestChatResult#52b08db to nil")
	}
	if err := b.ConsumeID(MessagesSetBotGuestChatResultRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.setBotGuestChatResult#52b08db: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *MessagesSetBotGuestChatResultRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.setBotGuestChatResult#52b08db to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.setBotGuestChatResult#52b08db: field query_id: %w", err)
		}
		s.QueryID = value
	}
	{
		value, err := DecodeInputBotInlineResult(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.setBotGuestChatResult#52b08db: field result: %w", err)
		}
		s.Result = value
	}
	return nil
}

// GetQueryID returns value of QueryID field.
func (s *MessagesSetBotGuestChatResultRequest) GetQueryID() (value int64) {
	if s == nil {
		return
	}
	return s.QueryID
}

// GetResult returns value of Result field.
func (s *MessagesSetBotGuestChatResultRequest) GetResult() (value InputBotInlineResultClass) {
	if s == nil {
		return
	}
	return s.Result
}

// MessagesSetBotGuestChatResult invokes method messages.setBotGuestChatResult#52b08db returning error if any.
//
// See https://core.telegram.org/method/messages.setBotGuestChatResult for reference.
func (c *Client) MessagesSetBotGuestChatResult(ctx context.Context, request *MessagesSetBotGuestChatResultRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
