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

// GetBotSimilarBotCountRequest represents TL type `getBotSimilarBotCount#b435c1e7`.
type GetBotSimilarBotCountRequest struct {
	// User identifier of the target bot
	BotUserID int64
	// Pass true to get the number of bots without sending network requests, or -1 if the
	// number of bots is unknown locally
	ReturnLocal bool
}

// GetBotSimilarBotCountRequestTypeID is TL type id of GetBotSimilarBotCountRequest.
const GetBotSimilarBotCountRequestTypeID = 0xb435c1e7

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

func (g *GetBotSimilarBotCountRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.BotUserID == 0) {
		return false
	}
	if !(g.ReturnLocal == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetBotSimilarBotCountRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getBotSimilarBotCount",
		ID:   GetBotSimilarBotCountRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "ReturnLocal",
			SchemaName: "return_local",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetBotSimilarBotCountRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getBotSimilarBotCount#b435c1e7 as nil")
	}
	b.PutID(GetBotSimilarBotCountRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetBotSimilarBotCountRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getBotSimilarBotCount#b435c1e7 as nil")
	}
	b.PutInt53(g.BotUserID)
	b.PutBool(g.ReturnLocal)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetBotSimilarBotCountRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getBotSimilarBotCount#b435c1e7 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getBotSimilarBotCount#b435c1e7: field bot_user_id: %w", err)
		}
		g.BotUserID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode getBotSimilarBotCount#b435c1e7: field return_local: %w", err)
		}
		g.ReturnLocal = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetBotSimilarBotCountRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getBotSimilarBotCount#b435c1e7 as nil")
	}
	b.ObjStart()
	b.PutID("getBotSimilarBotCount")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(g.BotUserID)
	b.Comma()
	b.FieldStart("return_local")
	b.PutBool(g.ReturnLocal)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getBotSimilarBotCount"); err != nil {
				return fmt.Errorf("unable to decode getBotSimilarBotCount#b435c1e7: %w", err)
			}
		case "bot_user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode getBotSimilarBotCount#b435c1e7: field bot_user_id: %w", err)
			}
			g.BotUserID = value
		case "return_local":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode getBotSimilarBotCount#b435c1e7: field return_local: %w", err)
			}
			g.ReturnLocal = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBotUserID returns value of BotUserID field.
func (g *GetBotSimilarBotCountRequest) GetBotUserID() (value int64) {
	if g == nil {
		return
	}
	return g.BotUserID
}

// GetReturnLocal returns value of ReturnLocal field.
func (g *GetBotSimilarBotCountRequest) GetReturnLocal() (value bool) {
	if g == nil {
		return
	}
	return g.ReturnLocal
}

// GetBotSimilarBotCount invokes method getBotSimilarBotCount#b435c1e7 returning error if any.
func (c *Client) GetBotSimilarBotCount(ctx context.Context, request *GetBotSimilarBotCountRequest) (*Count, error) {
	var result Count

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