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

// BroadcastRevenueTransactionProceeds represents TL type `broadcastRevenueTransactionProceeds#557e2cc4`.
// Describes earnings from sponsored messages in a channel in some time frame, see here
// »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/revenue
//
// See https://core.telegram.org/constructor/broadcastRevenueTransactionProceeds for reference.
type BroadcastRevenueTransactionProceeds struct {
	// Amount in the smallest unit of the cryptocurrency.
	Amount int64
	// Start unixtime for the timeframe.
	FromDate int
	// End unixtime for the timeframe.
	ToDate int
}

// BroadcastRevenueTransactionProceedsTypeID is TL type id of BroadcastRevenueTransactionProceeds.
const BroadcastRevenueTransactionProceedsTypeID = 0x557e2cc4

// construct implements constructor of BroadcastRevenueTransactionClass.
func (b BroadcastRevenueTransactionProceeds) construct() BroadcastRevenueTransactionClass { return &b }

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

	_ BroadcastRevenueTransactionClass = &BroadcastRevenueTransactionProceeds{}
)

func (b *BroadcastRevenueTransactionProceeds) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.Amount == 0) {
		return false
	}
	if !(b.FromDate == 0) {
		return false
	}
	if !(b.ToDate == 0) {
		return false
	}

	return true
}

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

// FillFrom fills BroadcastRevenueTransactionProceeds from given interface.
func (b *BroadcastRevenueTransactionProceeds) FillFrom(from interface {
	GetAmount() (value int64)
	GetFromDate() (value int)
	GetToDate() (value int)
}) {
	b.Amount = from.GetAmount()
	b.FromDate = from.GetFromDate()
	b.ToDate = from.GetToDate()
}

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

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

// TypeInfo returns info about TL type.
func (b *BroadcastRevenueTransactionProceeds) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "broadcastRevenueTransactionProceeds",
		ID:   BroadcastRevenueTransactionProceedsTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "FromDate",
			SchemaName: "from_date",
		},
		{
			Name:       "ToDate",
			SchemaName: "to_date",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (b *BroadcastRevenueTransactionProceeds) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode broadcastRevenueTransactionProceeds#557e2cc4 as nil")
	}
	buf.PutID(BroadcastRevenueTransactionProceedsTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BroadcastRevenueTransactionProceeds) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode broadcastRevenueTransactionProceeds#557e2cc4 as nil")
	}
	buf.PutLong(b.Amount)
	buf.PutInt(b.FromDate)
	buf.PutInt(b.ToDate)
	return nil
}

// Decode implements bin.Decoder.
func (b *BroadcastRevenueTransactionProceeds) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode broadcastRevenueTransactionProceeds#557e2cc4 to nil")
	}
	if err := buf.ConsumeID(BroadcastRevenueTransactionProceedsTypeID); err != nil {
		return fmt.Errorf("unable to decode broadcastRevenueTransactionProceeds#557e2cc4: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BroadcastRevenueTransactionProceeds) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode broadcastRevenueTransactionProceeds#557e2cc4 to nil")
	}
	{
		value, err := buf.Long()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionProceeds#557e2cc4: field amount: %w", err)
		}
		b.Amount = value
	}
	{
		value, err := buf.Int()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionProceeds#557e2cc4: field from_date: %w", err)
		}
		b.FromDate = value
	}
	{
		value, err := buf.Int()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionProceeds#557e2cc4: field to_date: %w", err)
		}
		b.ToDate = value
	}
	return nil
}

// GetAmount returns value of Amount field.
func (b *BroadcastRevenueTransactionProceeds) GetAmount() (value int64) {
	if b == nil {
		return
	}
	return b.Amount
}

// GetFromDate returns value of FromDate field.
func (b *BroadcastRevenueTransactionProceeds) GetFromDate() (value int) {
	if b == nil {
		return
	}
	return b.FromDate
}

// GetToDate returns value of ToDate field.
func (b *BroadcastRevenueTransactionProceeds) GetToDate() (value int) {
	if b == nil {
		return
	}
	return b.ToDate
}

// BroadcastRevenueTransactionWithdrawal represents TL type `broadcastRevenueTransactionWithdrawal#5a590978`.
// Describes a withdrawal of ad earnings »¹
//
// Links:
//  1. https://core.telegram.org/api/revenue#withdrawing-revenue
//
// See https://core.telegram.org/constructor/broadcastRevenueTransactionWithdrawal for reference.
type BroadcastRevenueTransactionWithdrawal struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the withdrawal is currently pending
	Pending bool
	// Whether the withdrawal has failed
	Failed bool
	// Amount withdrawn
	Amount int64
	// Withdrawal date
	Date int
	// Payment provider name
	Provider string
	// If neither pending nor failed are set, the transaction was completed successfully, and
	// this field will contain the point in time (Unix timestamp) when the withdrawal was
	// completed successfully.
	//
	// Use SetTransactionDate and GetTransactionDate helpers.
	TransactionDate int
	// If neither pending nor failed are set, the transaction was completed successfully, and
	// this field will contain a URL where the withdrawal transaction can be viewed.
	//
	// Use SetTransactionURL and GetTransactionURL helpers.
	TransactionURL string
}

// BroadcastRevenueTransactionWithdrawalTypeID is TL type id of BroadcastRevenueTransactionWithdrawal.
const BroadcastRevenueTransactionWithdrawalTypeID = 0x5a590978

// construct implements constructor of BroadcastRevenueTransactionClass.
func (b BroadcastRevenueTransactionWithdrawal) construct() BroadcastRevenueTransactionClass {
	return &b
}

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

	_ BroadcastRevenueTransactionClass = &BroadcastRevenueTransactionWithdrawal{}
)

func (b *BroadcastRevenueTransactionWithdrawal) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.Flags.Zero()) {
		return false
	}
	if !(b.Pending == false) {
		return false
	}
	if !(b.Failed == false) {
		return false
	}
	if !(b.Amount == 0) {
		return false
	}
	if !(b.Date == 0) {
		return false
	}
	if !(b.Provider == "") {
		return false
	}
	if !(b.TransactionDate == 0) {
		return false
	}
	if !(b.TransactionURL == "") {
		return false
	}

	return true
}

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

// FillFrom fills BroadcastRevenueTransactionWithdrawal from given interface.
func (b *BroadcastRevenueTransactionWithdrawal) FillFrom(from interface {
	GetPending() (value bool)
	GetFailed() (value bool)
	GetAmount() (value int64)
	GetDate() (value int)
	GetProvider() (value string)
	GetTransactionDate() (value int, ok bool)
	GetTransactionURL() (value string, ok bool)
}) {
	b.Pending = from.GetPending()
	b.Failed = from.GetFailed()
	b.Amount = from.GetAmount()
	b.Date = from.GetDate()
	b.Provider = from.GetProvider()
	if val, ok := from.GetTransactionDate(); ok {
		b.TransactionDate = val
	}

	if val, ok := from.GetTransactionURL(); ok {
		b.TransactionURL = val
	}

}

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

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

// TypeInfo returns info about TL type.
func (b *BroadcastRevenueTransactionWithdrawal) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "broadcastRevenueTransactionWithdrawal",
		ID:   BroadcastRevenueTransactionWithdrawalTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Pending",
			SchemaName: "pending",
			Null:       !b.Flags.Has(0),
		},
		{
			Name:       "Failed",
			SchemaName: "failed",
			Null:       !b.Flags.Has(2),
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Provider",
			SchemaName: "provider",
		},
		{
			Name:       "TransactionDate",
			SchemaName: "transaction_date",
			Null:       !b.Flags.Has(1),
		},
		{
			Name:       "TransactionURL",
			SchemaName: "transaction_url",
			Null:       !b.Flags.Has(1),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (b *BroadcastRevenueTransactionWithdrawal) SetFlags() {
	if !(b.Pending == false) {
		b.Flags.Set(0)
	}
	if !(b.Failed == false) {
		b.Flags.Set(2)
	}
	if !(b.TransactionDate == 0) {
		b.Flags.Set(1)
	}
	if !(b.TransactionURL == "") {
		b.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func (b *BroadcastRevenueTransactionWithdrawal) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode broadcastRevenueTransactionWithdrawal#5a590978 as nil")
	}
	buf.PutID(BroadcastRevenueTransactionWithdrawalTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BroadcastRevenueTransactionWithdrawal) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode broadcastRevenueTransactionWithdrawal#5a590978 as nil")
	}
	b.SetFlags()
	if err := b.Flags.Encode(buf); err != nil {
		return fmt.Errorf("unable to encode broadcastRevenueTransactionWithdrawal#5a590978: field flags: %w", err)
	}
	buf.PutLong(b.Amount)
	buf.PutInt(b.Date)
	buf.PutString(b.Provider)
	if b.Flags.Has(1) {
		buf.PutInt(b.TransactionDate)
	}
	if b.Flags.Has(1) {
		buf.PutString(b.TransactionURL)
	}
	return nil
}

// Decode implements bin.Decoder.
func (b *BroadcastRevenueTransactionWithdrawal) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode broadcastRevenueTransactionWithdrawal#5a590978 to nil")
	}
	if err := buf.ConsumeID(BroadcastRevenueTransactionWithdrawalTypeID); err != nil {
		return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BroadcastRevenueTransactionWithdrawal) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode broadcastRevenueTransactionWithdrawal#5a590978 to nil")
	}
	{
		if err := b.Flags.Decode(buf); err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: field flags: %w", err)
		}
	}
	b.Pending = b.Flags.Has(0)
	b.Failed = b.Flags.Has(2)
	{
		value, err := buf.Long()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: field amount: %w", err)
		}
		b.Amount = value
	}
	{
		value, err := buf.Int()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: field date: %w", err)
		}
		b.Date = value
	}
	{
		value, err := buf.String()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: field provider: %w", err)
		}
		b.Provider = value
	}
	if b.Flags.Has(1) {
		value, err := buf.Int()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: field transaction_date: %w", err)
		}
		b.TransactionDate = value
	}
	if b.Flags.Has(1) {
		value, err := buf.String()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionWithdrawal#5a590978: field transaction_url: %w", err)
		}
		b.TransactionURL = value
	}
	return nil
}

// SetPending sets value of Pending conditional field.
func (b *BroadcastRevenueTransactionWithdrawal) SetPending(value bool) {
	if value {
		b.Flags.Set(0)
		b.Pending = true
	} else {
		b.Flags.Unset(0)
		b.Pending = false
	}
}

// GetPending returns value of Pending conditional field.
func (b *BroadcastRevenueTransactionWithdrawal) GetPending() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(0)
}

// SetFailed sets value of Failed conditional field.
func (b *BroadcastRevenueTransactionWithdrawal) SetFailed(value bool) {
	if value {
		b.Flags.Set(2)
		b.Failed = true
	} else {
		b.Flags.Unset(2)
		b.Failed = false
	}
}

// GetFailed returns value of Failed conditional field.
func (b *BroadcastRevenueTransactionWithdrawal) GetFailed() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(2)
}

// GetAmount returns value of Amount field.
func (b *BroadcastRevenueTransactionWithdrawal) GetAmount() (value int64) {
	if b == nil {
		return
	}
	return b.Amount
}

// GetDate returns value of Date field.
func (b *BroadcastRevenueTransactionWithdrawal) GetDate() (value int) {
	if b == nil {
		return
	}
	return b.Date
}

// GetProvider returns value of Provider field.
func (b *BroadcastRevenueTransactionWithdrawal) GetProvider() (value string) {
	if b == nil {
		return
	}
	return b.Provider
}

// SetTransactionDate sets value of TransactionDate conditional field.
func (b *BroadcastRevenueTransactionWithdrawal) SetTransactionDate(value int) {
	b.Flags.Set(1)
	b.TransactionDate = value
}

// GetTransactionDate returns value of TransactionDate conditional field and
// boolean which is true if field was set.
func (b *BroadcastRevenueTransactionWithdrawal) GetTransactionDate() (value int, ok bool) {
	if b == nil {
		return
	}
	if !b.Flags.Has(1) {
		return value, false
	}
	return b.TransactionDate, true
}

// SetTransactionURL sets value of TransactionURL conditional field.
func (b *BroadcastRevenueTransactionWithdrawal) SetTransactionURL(value string) {
	b.Flags.Set(1)
	b.TransactionURL = value
}

// GetTransactionURL returns value of TransactionURL conditional field and
// boolean which is true if field was set.
func (b *BroadcastRevenueTransactionWithdrawal) GetTransactionURL() (value string, ok bool) {
	if b == nil {
		return
	}
	if !b.Flags.Has(1) {
		return value, false
	}
	return b.TransactionURL, true
}

// BroadcastRevenueTransactionRefund represents TL type `broadcastRevenueTransactionRefund#42d30d2e`.
// Describes a refund for failed withdrawal of ad earnings »¹
//
// Links:
//  1. https://core.telegram.org/api/revenue#withdrawing-revenue
//
// See https://core.telegram.org/constructor/broadcastRevenueTransactionRefund for reference.
type BroadcastRevenueTransactionRefund struct {
	// Amount refunded.
	Amount int64
	// Date of refund.
	Date int
	// Payment provider name.
	Provider string
}

// BroadcastRevenueTransactionRefundTypeID is TL type id of BroadcastRevenueTransactionRefund.
const BroadcastRevenueTransactionRefundTypeID = 0x42d30d2e

// construct implements constructor of BroadcastRevenueTransactionClass.
func (b BroadcastRevenueTransactionRefund) construct() BroadcastRevenueTransactionClass { return &b }

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

	_ BroadcastRevenueTransactionClass = &BroadcastRevenueTransactionRefund{}
)

func (b *BroadcastRevenueTransactionRefund) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.Amount == 0) {
		return false
	}
	if !(b.Date == 0) {
		return false
	}
	if !(b.Provider == "") {
		return false
	}

	return true
}

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

// FillFrom fills BroadcastRevenueTransactionRefund from given interface.
func (b *BroadcastRevenueTransactionRefund) FillFrom(from interface {
	GetAmount() (value int64)
	GetDate() (value int)
	GetProvider() (value string)
}) {
	b.Amount = from.GetAmount()
	b.Date = from.GetDate()
	b.Provider = from.GetProvider()
}

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

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

// TypeInfo returns info about TL type.
func (b *BroadcastRevenueTransactionRefund) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "broadcastRevenueTransactionRefund",
		ID:   BroadcastRevenueTransactionRefundTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Provider",
			SchemaName: "provider",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (b *BroadcastRevenueTransactionRefund) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode broadcastRevenueTransactionRefund#42d30d2e as nil")
	}
	buf.PutID(BroadcastRevenueTransactionRefundTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BroadcastRevenueTransactionRefund) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode broadcastRevenueTransactionRefund#42d30d2e as nil")
	}
	buf.PutLong(b.Amount)
	buf.PutInt(b.Date)
	buf.PutString(b.Provider)
	return nil
}

// Decode implements bin.Decoder.
func (b *BroadcastRevenueTransactionRefund) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode broadcastRevenueTransactionRefund#42d30d2e to nil")
	}
	if err := buf.ConsumeID(BroadcastRevenueTransactionRefundTypeID); err != nil {
		return fmt.Errorf("unable to decode broadcastRevenueTransactionRefund#42d30d2e: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BroadcastRevenueTransactionRefund) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode broadcastRevenueTransactionRefund#42d30d2e to nil")
	}
	{
		value, err := buf.Long()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionRefund#42d30d2e: field amount: %w", err)
		}
		b.Amount = value
	}
	{
		value, err := buf.Int()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionRefund#42d30d2e: field date: %w", err)
		}
		b.Date = value
	}
	{
		value, err := buf.String()
		if err != nil {
			return fmt.Errorf("unable to decode broadcastRevenueTransactionRefund#42d30d2e: field provider: %w", err)
		}
		b.Provider = value
	}
	return nil
}

// GetAmount returns value of Amount field.
func (b *BroadcastRevenueTransactionRefund) GetAmount() (value int64) {
	if b == nil {
		return
	}
	return b.Amount
}

// GetDate returns value of Date field.
func (b *BroadcastRevenueTransactionRefund) GetDate() (value int) {
	if b == nil {
		return
	}
	return b.Date
}

// GetProvider returns value of Provider field.
func (b *BroadcastRevenueTransactionRefund) GetProvider() (value string) {
	if b == nil {
		return
	}
	return b.Provider
}

// BroadcastRevenueTransactionClassName is schema name of BroadcastRevenueTransactionClass.
const BroadcastRevenueTransactionClassName = "BroadcastRevenueTransaction"

// BroadcastRevenueTransactionClass represents BroadcastRevenueTransaction generic type.
//
// See https://core.telegram.org/type/BroadcastRevenueTransaction for reference.
//
// Example:
//
//	g, err := tg.DecodeBroadcastRevenueTransaction(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.BroadcastRevenueTransactionProceeds: // broadcastRevenueTransactionProceeds#557e2cc4
//	case *tg.BroadcastRevenueTransactionWithdrawal: // broadcastRevenueTransactionWithdrawal#5a590978
//	case *tg.BroadcastRevenueTransactionRefund: // broadcastRevenueTransactionRefund#42d30d2e
//	default: panic(v)
//	}
type BroadcastRevenueTransactionClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() BroadcastRevenueTransactionClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Amount in the smallest unit of the cryptocurrency.
	GetAmount() (value int64)
}

// DecodeBroadcastRevenueTransaction implements binary de-serialization for BroadcastRevenueTransactionClass.
func DecodeBroadcastRevenueTransaction(buf *bin.Buffer) (BroadcastRevenueTransactionClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case BroadcastRevenueTransactionProceedsTypeID:
		// Decoding broadcastRevenueTransactionProceeds#557e2cc4.
		v := BroadcastRevenueTransactionProceeds{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BroadcastRevenueTransactionClass: %w", err)
		}
		return &v, nil
	case BroadcastRevenueTransactionWithdrawalTypeID:
		// Decoding broadcastRevenueTransactionWithdrawal#5a590978.
		v := BroadcastRevenueTransactionWithdrawal{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BroadcastRevenueTransactionClass: %w", err)
		}
		return &v, nil
	case BroadcastRevenueTransactionRefundTypeID:
		// Decoding broadcastRevenueTransactionRefund#42d30d2e.
		v := BroadcastRevenueTransactionRefund{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BroadcastRevenueTransactionClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode BroadcastRevenueTransactionClass: %w", bin.NewUnexpectedID(id))
	}
}

// BroadcastRevenueTransaction boxes the BroadcastRevenueTransactionClass providing a helper.
type BroadcastRevenueTransactionBox struct {
	BroadcastRevenueTransaction BroadcastRevenueTransactionClass
}

// Decode implements bin.Decoder for BroadcastRevenueTransactionBox.
func (b *BroadcastRevenueTransactionBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode BroadcastRevenueTransactionBox to nil")
	}
	v, err := DecodeBroadcastRevenueTransaction(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.BroadcastRevenueTransaction = v
	return nil
}

// Encode implements bin.Encode for BroadcastRevenueTransactionBox.
func (b *BroadcastRevenueTransactionBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.BroadcastRevenueTransaction == nil {
		return fmt.Errorf("unable to encode BroadcastRevenueTransactionClass as nil")
	}
	return b.BroadcastRevenueTransaction.Encode(buf)
}
