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

// GetEmojiSuggestionsURLRequest represents TL type `getEmojiSuggestionsUrl#ac4f1b2f`.
type GetEmojiSuggestionsURLRequest struct {
	// Language code for which the emoji replacements will be suggested
	LanguageCode string
}

// GetEmojiSuggestionsURLRequestTypeID is TL type id of GetEmojiSuggestionsURLRequest.
const GetEmojiSuggestionsURLRequestTypeID = 0xac4f1b2f

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetEmojiSuggestionsURLRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getEmojiSuggestionsUrl",
		ID:   GetEmojiSuggestionsURLRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "LanguageCode",
			SchemaName: "language_code",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetEmojiSuggestionsURLRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getEmojiSuggestionsUrl#ac4f1b2f as nil")
	}
	b.PutID(GetEmojiSuggestionsURLRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetEmojiSuggestionsURLRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getEmojiSuggestionsUrl#ac4f1b2f as nil")
	}
	b.PutString(g.LanguageCode)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetEmojiSuggestionsURLRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getEmojiSuggestionsUrl#ac4f1b2f to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getEmojiSuggestionsUrl#ac4f1b2f: field language_code: %w", err)
		}
		g.LanguageCode = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetEmojiSuggestionsURLRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getEmojiSuggestionsUrl#ac4f1b2f as nil")
	}
	b.ObjStart()
	b.PutID("getEmojiSuggestionsUrl")
	b.Comma()
	b.FieldStart("language_code")
	b.PutString(g.LanguageCode)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetLanguageCode returns value of LanguageCode field.
func (g *GetEmojiSuggestionsURLRequest) GetLanguageCode() (value string) {
	if g == nil {
		return
	}
	return g.LanguageCode
}

// GetEmojiSuggestionsURL invokes method getEmojiSuggestionsUrl#ac4f1b2f returning error if any.
func (c *Client) GetEmojiSuggestionsURL(ctx context.Context, languagecode string) (*HTTPURL, error) {
	var result HTTPURL

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