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

// PaymentsGetStarGiftUpgradeAttributesRequest represents TL type `payments.getStarGiftUpgradeAttributes#6d038b58`.
//
// See https://core.telegram.org/method/payments.getStarGiftUpgradeAttributes for reference.
type PaymentsGetStarGiftUpgradeAttributesRequest struct {
	// GiftID field of PaymentsGetStarGiftUpgradeAttributesRequest.
	GiftID int64
}

// PaymentsGetStarGiftUpgradeAttributesRequestTypeID is TL type id of PaymentsGetStarGiftUpgradeAttributesRequest.
const PaymentsGetStarGiftUpgradeAttributesRequestTypeID = 0x6d038b58

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

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

	return true
}

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

// FillFrom fills PaymentsGetStarGiftUpgradeAttributesRequest from given interface.
func (g *PaymentsGetStarGiftUpgradeAttributesRequest) FillFrom(from interface {
	GetGiftID() (value int64)
}) {
	g.GiftID = from.GetGiftID()
}

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

// TypeName returns name of type in TL schema.
func (*PaymentsGetStarGiftUpgradeAttributesRequest) TypeName() string {
	return "payments.getStarGiftUpgradeAttributes"
}

// TypeInfo returns info about TL type.
func (g *PaymentsGetStarGiftUpgradeAttributesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.getStarGiftUpgradeAttributes",
		ID:   PaymentsGetStarGiftUpgradeAttributesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GiftID",
			SchemaName: "gift_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PaymentsGetStarGiftUpgradeAttributesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarGiftUpgradeAttributes#6d038b58 as nil")
	}
	b.PutID(PaymentsGetStarGiftUpgradeAttributesRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetStarGiftUpgradeAttributesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarGiftUpgradeAttributes#6d038b58 as nil")
	}
	b.PutLong(g.GiftID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetStarGiftUpgradeAttributesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getStarGiftUpgradeAttributes#6d038b58 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getStarGiftUpgradeAttributes#6d038b58: field gift_id: %w", err)
		}
		g.GiftID = value
	}
	return nil
}

// GetGiftID returns value of GiftID field.
func (g *PaymentsGetStarGiftUpgradeAttributesRequest) GetGiftID() (value int64) {
	if g == nil {
		return
	}
	return g.GiftID
}

// PaymentsGetStarGiftUpgradeAttributes invokes method payments.getStarGiftUpgradeAttributes#6d038b58 returning error if any.
//
// See https://core.telegram.org/method/payments.getStarGiftUpgradeAttributes for reference.
func (c *Client) PaymentsGetStarGiftUpgradeAttributes(ctx context.Context, giftid int64) (*PaymentsStarGiftUpgradeAttributes, error) {
	var result PaymentsStarGiftUpgradeAttributes

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