// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// MessagesGetMyStickersRequest represents TL type `messages.getMyStickers#d0b5e1fc`.
// Fetch all stickersets »¹ owned by the current user.
//
// Links:
//  1. https://core.telegram.org/api/stickers
//
// See https://core.telegram.org/method/messages.getMyStickers for reference.
type MessagesGetMyStickersRequest struct {
	// Offsets for pagination, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	OffsetID int64
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
}

// MessagesGetMyStickersRequestTypeID is TL type id of MessagesGetMyStickersRequest.
const MessagesGetMyStickersRequestTypeID = 0xd0b5e1fc

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

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

	return true
}

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

// FillFrom fills MessagesGetMyStickersRequest from given interface.
func (g *MessagesGetMyStickersRequest) FillFrom(from interface {
	GetOffsetID() (value int64)
	GetLimit() (value int)
}) {
	g.OffsetID = from.GetOffsetID()
	g.Limit = from.GetLimit()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesGetMyStickersRequest) TypeName() string {
	return "messages.getMyStickers"
}

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

// Encode implements bin.Encoder.
func (g *MessagesGetMyStickersRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getMyStickers#d0b5e1fc as nil")
	}
	b.PutID(MessagesGetMyStickersRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *MessagesGetMyStickersRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getMyStickers#d0b5e1fc as nil")
	}
	b.PutLong(g.OffsetID)
	b.PutInt(g.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *MessagesGetMyStickersRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getMyStickers#d0b5e1fc to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.getMyStickers#d0b5e1fc: field offset_id: %w", err)
		}
		g.OffsetID = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.getMyStickers#d0b5e1fc: field limit: %w", err)
		}
		g.Limit = value
	}
	return nil
}

// GetOffsetID returns value of OffsetID field.
func (g *MessagesGetMyStickersRequest) GetOffsetID() (value int64) {
	if g == nil {
		return
	}
	return g.OffsetID
}

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

// MessagesGetMyStickers invokes method messages.getMyStickers#d0b5e1fc returning error if any.
// Fetch all stickersets »¹ owned by the current user.
//
// Links:
//  1. https://core.telegram.org/api/stickers
//
// See https://core.telegram.org/method/messages.getMyStickers for reference.
func (c *Client) MessagesGetMyStickers(ctx context.Context, request *MessagesGetMyStickersRequest) (*MessagesMyStickers, error) {
	var result MessagesMyStickers

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