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

// GetPaidMessageRevenueRequest represents TL type `getPaidMessageRevenue#75d05b2e`.
type GetPaidMessageRevenueRequest struct {
	// Identifier of the user
	UserID int64
}

// GetPaidMessageRevenueRequestTypeID is TL type id of GetPaidMessageRevenueRequest.
const GetPaidMessageRevenueRequestTypeID = 0x75d05b2e

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetPaidMessageRevenueRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPaidMessageRevenue",
		ID:   GetPaidMessageRevenueRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPaidMessageRevenueRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPaidMessageRevenue#75d05b2e as nil")
	}
	b.PutID(GetPaidMessageRevenueRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPaidMessageRevenueRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPaidMessageRevenue#75d05b2e as nil")
	}
	b.PutInt53(g.UserID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetPaidMessageRevenueRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPaidMessageRevenue#75d05b2e to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getPaidMessageRevenue#75d05b2e: field user_id: %w", err)
		}
		g.UserID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPaidMessageRevenueRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPaidMessageRevenue#75d05b2e as nil")
	}
	b.ObjStart()
	b.PutID("getPaidMessageRevenue")
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(g.UserID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getPaidMessageRevenue"); err != nil {
				return fmt.Errorf("unable to decode getPaidMessageRevenue#75d05b2e: %w", err)
			}
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode getPaidMessageRevenue#75d05b2e: field user_id: %w", err)
			}
			g.UserID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserID returns value of UserID field.
func (g *GetPaidMessageRevenueRequest) GetUserID() (value int64) {
	if g == nil {
		return
	}
	return g.UserID
}

// GetPaidMessageRevenue invokes method getPaidMessageRevenue#75d05b2e returning error if any.
func (c *Client) GetPaidMessageRevenue(ctx context.Context, userid int64) (*StarCount, error) {
	var result StarCount

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