// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// GetBusinessConnectedBotRequest represents TL type `getBusinessConnectedBot#364da7c3`.
type GetBusinessConnectedBotRequest struct {
}

// GetBusinessConnectedBotRequestTypeID is TL type id of GetBusinessConnectedBotRequest.
const GetBusinessConnectedBotRequestTypeID = 0x364da7c3

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

func (g *GetBusinessConnectedBotRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*GetBusinessConnectedBotRequest) TypeName() string {
	return "getBusinessConnectedBot"
}

// TypeInfo returns info about TL type.
func (g *GetBusinessConnectedBotRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getBusinessConnectedBot",
		ID:   GetBusinessConnectedBotRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetBusinessConnectedBotRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getBusinessConnectedBot#364da7c3 as nil")
	}
	b.PutID(GetBusinessConnectedBotRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetBusinessConnectedBotRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getBusinessConnectedBot#364da7c3 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GetBusinessConnectedBotRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getBusinessConnectedBot#364da7c3 to nil")
	}
	if err := b.ConsumeID(GetBusinessConnectedBotRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getBusinessConnectedBot#364da7c3: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetBusinessConnectedBotRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getBusinessConnectedBot#364da7c3 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetBusinessConnectedBotRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getBusinessConnectedBot#364da7c3 as nil")
	}
	b.ObjStart()
	b.PutID("getBusinessConnectedBot")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetBusinessConnectedBotRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getBusinessConnectedBot#364da7c3 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getBusinessConnectedBot"); err != nil {
				return fmt.Errorf("unable to decode getBusinessConnectedBot#364da7c3: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBusinessConnectedBot invokes method getBusinessConnectedBot#364da7c3 returning error if any.
func (c *Client) GetBusinessConnectedBot(ctx context.Context) (*BusinessConnectedBot, error) {
	var result BusinessConnectedBot

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