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

// GetPremiumStickersRequest represents TL type `getPremiumStickers#ef410a50`.
type GetPremiumStickersRequest struct {
	// The maximum number of stickers to be returned; 0-100
	Limit int32
}

// GetPremiumStickersRequestTypeID is TL type id of GetPremiumStickersRequest.
const GetPremiumStickersRequestTypeID = 0xef410a50

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

func (g *GetPremiumStickersRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Limit == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetPremiumStickersRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPremiumStickers",
		ID:   GetPremiumStickersRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPremiumStickersRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumStickers#ef410a50 as nil")
	}
	b.PutID(GetPremiumStickersRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPremiumStickersRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumStickers#ef410a50 as nil")
	}
	b.PutInt32(g.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetPremiumStickersRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPremiumStickers#ef410a50 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getPremiumStickers#ef410a50: field limit: %w", err)
		}
		g.Limit = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPremiumStickersRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumStickers#ef410a50 as nil")
	}
	b.ObjStart()
	b.PutID("getPremiumStickers")
	b.Comma()
	b.FieldStart("limit")
	b.PutInt32(g.Limit)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetLimit returns value of Limit field.
func (g *GetPremiumStickersRequest) GetLimit() (value int32) {
	if g == nil {
		return
	}
	return g.Limit
}

// GetPremiumStickers invokes method getPremiumStickers#ef410a50 returning error if any.
func (c *Client) GetPremiumStickers(ctx context.Context, limit int32) (*Stickers, error) {
	var result Stickers

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