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

// AccountGetPaidMessagesRevenueRequest represents TL type `account.getPaidMessagesRevenue#f1266f38`.
//
// See https://core.telegram.org/method/account.getPaidMessagesRevenue for reference.
type AccountGetPaidMessagesRevenueRequest struct {
	// UserID field of AccountGetPaidMessagesRevenueRequest.
	UserID InputUserClass
}

// AccountGetPaidMessagesRevenueRequestTypeID is TL type id of AccountGetPaidMessagesRevenueRequest.
const AccountGetPaidMessagesRevenueRequestTypeID = 0xf1266f38

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

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

	return true
}

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

// FillFrom fills AccountGetPaidMessagesRevenueRequest from given interface.
func (g *AccountGetPaidMessagesRevenueRequest) FillFrom(from interface {
	GetUserID() (value InputUserClass)
}) {
	g.UserID = from.GetUserID()
}

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

// TypeName returns name of type in TL schema.
func (*AccountGetPaidMessagesRevenueRequest) TypeName() string {
	return "account.getPaidMessagesRevenue"
}

// TypeInfo returns info about TL type.
func (g *AccountGetPaidMessagesRevenueRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.getPaidMessagesRevenue",
		ID:   AccountGetPaidMessagesRevenueRequestTypeID,
	}
	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 *AccountGetPaidMessagesRevenueRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getPaidMessagesRevenue#f1266f38 as nil")
	}
	b.PutID(AccountGetPaidMessagesRevenueRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *AccountGetPaidMessagesRevenueRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode account.getPaidMessagesRevenue#f1266f38 as nil")
	}
	if g.UserID == nil {
		return fmt.Errorf("unable to encode account.getPaidMessagesRevenue#f1266f38: field user_id is nil")
	}
	if err := g.UserID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.getPaidMessagesRevenue#f1266f38: field user_id: %w", err)
	}
	return nil
}

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

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

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

// AccountGetPaidMessagesRevenue invokes method account.getPaidMessagesRevenue#f1266f38 returning error if any.
//
// See https://core.telegram.org/method/account.getPaidMessagesRevenue for reference.
func (c *Client) AccountGetPaidMessagesRevenue(ctx context.Context, userid InputUserClass) (*AccountPaidMessagesRevenue, error) {
	var result AccountPaidMessagesRevenue

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