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

// GetPremiumGiveawayPaymentOptionsRequest represents TL type `getPremiumGiveawayPaymentOptions#48d8ce09`.
type GetPremiumGiveawayPaymentOptionsRequest struct {
	// Identifier of the supergroup or channel chat, which will be automatically boosted by
	// receivers of the gift codes and which is administered by the user
	BoostedChatID int64
}

// GetPremiumGiveawayPaymentOptionsRequestTypeID is TL type id of GetPremiumGiveawayPaymentOptionsRequest.
const GetPremiumGiveawayPaymentOptionsRequestTypeID = 0x48d8ce09

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

func (g *GetPremiumGiveawayPaymentOptionsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.BoostedChatID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetPremiumGiveawayPaymentOptionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPremiumGiveawayPaymentOptions",
		ID:   GetPremiumGiveawayPaymentOptionsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BoostedChatID",
			SchemaName: "boosted_chat_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPremiumGiveawayPaymentOptionsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumGiveawayPaymentOptions#48d8ce09 as nil")
	}
	b.PutID(GetPremiumGiveawayPaymentOptionsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPremiumGiveawayPaymentOptionsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumGiveawayPaymentOptions#48d8ce09 as nil")
	}
	b.PutInt53(g.BoostedChatID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetPremiumGiveawayPaymentOptionsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPremiumGiveawayPaymentOptions#48d8ce09 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getPremiumGiveawayPaymentOptions#48d8ce09: field boosted_chat_id: %w", err)
		}
		g.BoostedChatID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPremiumGiveawayPaymentOptionsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumGiveawayPaymentOptions#48d8ce09 as nil")
	}
	b.ObjStart()
	b.PutID("getPremiumGiveawayPaymentOptions")
	b.Comma()
	b.FieldStart("boosted_chat_id")
	b.PutInt53(g.BoostedChatID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getPremiumGiveawayPaymentOptions"); err != nil {
				return fmt.Errorf("unable to decode getPremiumGiveawayPaymentOptions#48d8ce09: %w", err)
			}
		case "boosted_chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode getPremiumGiveawayPaymentOptions#48d8ce09: field boosted_chat_id: %w", err)
			}
			g.BoostedChatID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBoostedChatID returns value of BoostedChatID field.
func (g *GetPremiumGiveawayPaymentOptionsRequest) GetBoostedChatID() (value int64) {
	if g == nil {
		return
	}
	return g.BoostedChatID
}

// GetPremiumGiveawayPaymentOptions invokes method getPremiumGiveawayPaymentOptions#48d8ce09 returning error if any.
func (c *Client) GetPremiumGiveawayPaymentOptions(ctx context.Context, boostedchatid int64) (*PremiumGiveawayPaymentOptions, error) {
	var result PremiumGiveawayPaymentOptions

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