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

// GetSuggestedStickerSetNameRequest represents TL type `getSuggestedStickerSetName#b0120840`.
type GetSuggestedStickerSetNameRequest struct {
	// Sticker set title; 1-64 characters
	Title string
}

// GetSuggestedStickerSetNameRequestTypeID is TL type id of GetSuggestedStickerSetNameRequest.
const GetSuggestedStickerSetNameRequestTypeID = 0xb0120840

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

func (g *GetSuggestedStickerSetNameRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Title == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetSuggestedStickerSetNameRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getSuggestedStickerSetName",
		ID:   GetSuggestedStickerSetNameRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Title",
			SchemaName: "title",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetSuggestedStickerSetNameRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getSuggestedStickerSetName#b0120840 as nil")
	}
	b.PutID(GetSuggestedStickerSetNameRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetSuggestedStickerSetNameRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getSuggestedStickerSetName#b0120840 as nil")
	}
	b.PutString(g.Title)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetSuggestedStickerSetNameRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getSuggestedStickerSetName#b0120840 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getSuggestedStickerSetName#b0120840: field title: %w", err)
		}
		g.Title = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetSuggestedStickerSetNameRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getSuggestedStickerSetName#b0120840 as nil")
	}
	b.ObjStart()
	b.PutID("getSuggestedStickerSetName")
	b.Comma()
	b.FieldStart("title")
	b.PutString(g.Title)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getSuggestedStickerSetName"); err != nil {
				return fmt.Errorf("unable to decode getSuggestedStickerSetName#b0120840: %w", err)
			}
		case "title":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode getSuggestedStickerSetName#b0120840: field title: %w", err)
			}
			g.Title = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTitle returns value of Title field.
func (g *GetSuggestedStickerSetNameRequest) GetTitle() (value string) {
	if g == nil {
		return
	}
	return g.Title
}

// GetSuggestedStickerSetName invokes method getSuggestedStickerSetName#b0120840 returning error if any.
func (c *Client) GetSuggestedStickerSetName(ctx context.Context, title string) (*Text, error) {
	var result Text

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