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

// GetPremiumInfoStickerRequest represents TL type `getPremiumInfoSticker#79ce4a9b`.
type GetPremiumInfoStickerRequest struct {
	// Number of months the Telegram Premium subscription will be active
	MonthCount int32
}

// GetPremiumInfoStickerRequestTypeID is TL type id of GetPremiumInfoStickerRequest.
const GetPremiumInfoStickerRequestTypeID = 0x79ce4a9b

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetPremiumInfoStickerRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPremiumInfoSticker",
		ID:   GetPremiumInfoStickerRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "MonthCount",
			SchemaName: "month_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPremiumInfoStickerRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumInfoSticker#79ce4a9b as nil")
	}
	b.PutID(GetPremiumInfoStickerRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPremiumInfoStickerRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumInfoSticker#79ce4a9b as nil")
	}
	b.PutInt32(g.MonthCount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetPremiumInfoStickerRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPremiumInfoSticker#79ce4a9b to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getPremiumInfoSticker#79ce4a9b: field month_count: %w", err)
		}
		g.MonthCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPremiumInfoStickerRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumInfoSticker#79ce4a9b as nil")
	}
	b.ObjStart()
	b.PutID("getPremiumInfoSticker")
	b.Comma()
	b.FieldStart("month_count")
	b.PutInt32(g.MonthCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetMonthCount returns value of MonthCount field.
func (g *GetPremiumInfoStickerRequest) GetMonthCount() (value int32) {
	if g == nil {
		return
	}
	return g.MonthCount
}

// GetPremiumInfoSticker invokes method getPremiumInfoSticker#79ce4a9b returning error if any.
func (c *Client) GetPremiumInfoSticker(ctx context.Context, monthcount int32) (*Sticker, error) {
	var result Sticker

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