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

// GetChatRevenueTransactionsRequest represents TL type `getChatRevenueTransactions#472f0715`.
type GetChatRevenueTransactionsRequest struct {
	// Chat identifier
	ChatID int64
	// Number of transactions to skip
	Offset int32
	// The maximum number of transactions to be returned; up to 200
	Limit int32
}

// GetChatRevenueTransactionsRequestTypeID is TL type id of GetChatRevenueTransactionsRequest.
const GetChatRevenueTransactionsRequestTypeID = 0x472f0715

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetChatRevenueTransactionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getChatRevenueTransactions",
		ID:   GetChatRevenueTransactionsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetChatRevenueTransactionsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatRevenueTransactions#472f0715 as nil")
	}
	b.PutID(GetChatRevenueTransactionsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetChatRevenueTransactionsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatRevenueTransactions#472f0715 as nil")
	}
	b.PutInt53(g.ChatID)
	b.PutInt32(g.Offset)
	b.PutInt32(g.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetChatRevenueTransactionsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getChatRevenueTransactions#472f0715 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getChatRevenueTransactions#472f0715: field chat_id: %w", err)
		}
		g.ChatID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getChatRevenueTransactions#472f0715: field offset: %w", err)
		}
		g.Offset = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getChatRevenueTransactions#472f0715: field limit: %w", err)
		}
		g.Limit = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetChatRevenueTransactionsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getChatRevenueTransactions#472f0715 as nil")
	}
	b.ObjStart()
	b.PutID("getChatRevenueTransactions")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(g.ChatID)
	b.Comma()
	b.FieldStart("offset")
	b.PutInt32(g.Offset)
	b.Comma()
	b.FieldStart("limit")
	b.PutInt32(g.Limit)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetChatID returns value of ChatID field.
func (g *GetChatRevenueTransactionsRequest) GetChatID() (value int64) {
	if g == nil {
		return
	}
	return g.ChatID
}

// GetOffset returns value of Offset field.
func (g *GetChatRevenueTransactionsRequest) GetOffset() (value int32) {
	if g == nil {
		return
	}
	return g.Offset
}

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

// GetChatRevenueTransactions invokes method getChatRevenueTransactions#472f0715 returning error if any.
func (c *Client) GetChatRevenueTransactions(ctx context.Context, request *GetChatRevenueTransactionsRequest) (*ChatRevenueTransactions, error) {
	var result ChatRevenueTransactions

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