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

// GetStarPaymentOptionsRequest represents TL type `getStarPaymentOptions#6d930644`.
type GetStarPaymentOptionsRequest struct {
}

// GetStarPaymentOptionsRequestTypeID is TL type id of GetStarPaymentOptionsRequest.
const GetStarPaymentOptionsRequestTypeID = 0x6d930644

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

func (g *GetStarPaymentOptionsRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetStarPaymentOptionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getStarPaymentOptions",
		ID:   GetStarPaymentOptionsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetStarPaymentOptionsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getStarPaymentOptions#6d930644 as nil")
	}
	b.PutID(GetStarPaymentOptionsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetStarPaymentOptionsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getStarPaymentOptions#6d930644 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetStarPaymentOptionsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getStarPaymentOptions#6d930644 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetStarPaymentOptionsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getStarPaymentOptions#6d930644 as nil")
	}
	b.ObjStart()
	b.PutID("getStarPaymentOptions")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getStarPaymentOptions"); err != nil {
				return fmt.Errorf("unable to decode getStarPaymentOptions#6d930644: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetStarPaymentOptions invokes method getStarPaymentOptions#6d930644 returning error if any.
func (c *Client) GetStarPaymentOptions(ctx context.Context) (*StarPaymentOptions, error) {
	var result StarPaymentOptions

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