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

// GetStarRevenueStatisticsRequest represents TL type `getStarRevenueStatistics#f07b4517`.
type GetStarRevenueStatisticsRequest struct {
	// Identifier of the owner of the Telegram Stars; can be identifier of the current user,
	// an owned bot, or a supergroup or a channel chat with supergroupFullInfo
	// can_get_star_revenue_statistics == true
	OwnerID MessageSenderClass
	// Pass true if a dark theme is used by the application
	IsDark bool
}

// GetStarRevenueStatisticsRequestTypeID is TL type id of GetStarRevenueStatisticsRequest.
const GetStarRevenueStatisticsRequestTypeID = 0xf07b4517

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

func (g *GetStarRevenueStatisticsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.OwnerID == nil) {
		return false
	}
	if !(g.IsDark == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetStarRevenueStatisticsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getStarRevenueStatistics",
		ID:   GetStarRevenueStatisticsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "OwnerID",
			SchemaName: "owner_id",
		},
		{
			Name:       "IsDark",
			SchemaName: "is_dark",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetStarRevenueStatisticsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getStarRevenueStatistics#f07b4517 as nil")
	}
	b.PutID(GetStarRevenueStatisticsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetStarRevenueStatisticsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getStarRevenueStatistics#f07b4517 as nil")
	}
	if g.OwnerID == nil {
		return fmt.Errorf("unable to encode getStarRevenueStatistics#f07b4517: field owner_id is nil")
	}
	if err := g.OwnerID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode getStarRevenueStatistics#f07b4517: field owner_id: %w", err)
	}
	b.PutBool(g.IsDark)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetStarRevenueStatisticsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getStarRevenueStatistics#f07b4517 to nil")
	}
	{
		value, err := DecodeMessageSender(b)
		if err != nil {
			return fmt.Errorf("unable to decode getStarRevenueStatistics#f07b4517: field owner_id: %w", err)
		}
		g.OwnerID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode getStarRevenueStatistics#f07b4517: field is_dark: %w", err)
		}
		g.IsDark = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetStarRevenueStatisticsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getStarRevenueStatistics#f07b4517 as nil")
	}
	b.ObjStart()
	b.PutID("getStarRevenueStatistics")
	b.Comma()
	b.FieldStart("owner_id")
	if g.OwnerID == nil {
		return fmt.Errorf("unable to encode getStarRevenueStatistics#f07b4517: field owner_id is nil")
	}
	if err := g.OwnerID.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode getStarRevenueStatistics#f07b4517: field owner_id: %w", err)
	}
	b.Comma()
	b.FieldStart("is_dark")
	b.PutBool(g.IsDark)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getStarRevenueStatistics"); err != nil {
				return fmt.Errorf("unable to decode getStarRevenueStatistics#f07b4517: %w", err)
			}
		case "owner_id":
			value, err := DecodeTDLibJSONMessageSender(b)
			if err != nil {
				return fmt.Errorf("unable to decode getStarRevenueStatistics#f07b4517: field owner_id: %w", err)
			}
			g.OwnerID = value
		case "is_dark":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode getStarRevenueStatistics#f07b4517: field is_dark: %w", err)
			}
			g.IsDark = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetOwnerID returns value of OwnerID field.
func (g *GetStarRevenueStatisticsRequest) GetOwnerID() (value MessageSenderClass) {
	if g == nil {
		return
	}
	return g.OwnerID
}

// GetIsDark returns value of IsDark field.
func (g *GetStarRevenueStatisticsRequest) GetIsDark() (value bool) {
	if g == nil {
		return
	}
	return g.IsDark
}

// GetStarRevenueStatistics invokes method getStarRevenueStatistics#f07b4517 returning error if any.
func (c *Client) GetStarRevenueStatistics(ctx context.Context, request *GetStarRevenueStatisticsRequest) (*StarRevenueStatistics, error) {
	var result StarRevenueStatistics

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