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

// PaymentsUpdateStarGiftPriceRequest represents TL type `payments.updateStarGiftPrice#edbe6ccb`.
// A collectible gift we own »¹ can be put up for sale on the gift marketplace »²
// with this method, see here »³ for more info.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://telegram.org/blog/gift-marketplace-and-more
//  3. https://core.telegram.org/api/gifts#reselling-collectible-gifts
//
// See https://core.telegram.org/method/payments.updateStarGiftPrice for reference.
type PaymentsUpdateStarGiftPriceRequest struct {
	// The gift to resell.
	Stargift InputSavedStarGiftClass
	// Resale price of the gift.
	ResellAmount StarsAmountClass
}

// PaymentsUpdateStarGiftPriceRequestTypeID is TL type id of PaymentsUpdateStarGiftPriceRequest.
const PaymentsUpdateStarGiftPriceRequestTypeID = 0xedbe6ccb

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

func (u *PaymentsUpdateStarGiftPriceRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.Stargift == nil) {
		return false
	}
	if !(u.ResellAmount == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsUpdateStarGiftPriceRequest from given interface.
func (u *PaymentsUpdateStarGiftPriceRequest) FillFrom(from interface {
	GetStargift() (value InputSavedStarGiftClass)
	GetResellAmount() (value StarsAmountClass)
}) {
	u.Stargift = from.GetStargift()
	u.ResellAmount = from.GetResellAmount()
}

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

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

// TypeInfo returns info about TL type.
func (u *PaymentsUpdateStarGiftPriceRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.updateStarGiftPrice",
		ID:   PaymentsUpdateStarGiftPriceRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Stargift",
			SchemaName: "stargift",
		},
		{
			Name:       "ResellAmount",
			SchemaName: "resell_amount",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *PaymentsUpdateStarGiftPriceRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode payments.updateStarGiftPrice#edbe6ccb as nil")
	}
	b.PutID(PaymentsUpdateStarGiftPriceRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *PaymentsUpdateStarGiftPriceRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode payments.updateStarGiftPrice#edbe6ccb as nil")
	}
	if u.Stargift == nil {
		return fmt.Errorf("unable to encode payments.updateStarGiftPrice#edbe6ccb: field stargift is nil")
	}
	if err := u.Stargift.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.updateStarGiftPrice#edbe6ccb: field stargift: %w", err)
	}
	if u.ResellAmount == nil {
		return fmt.Errorf("unable to encode payments.updateStarGiftPrice#edbe6ccb: field resell_amount is nil")
	}
	if err := u.ResellAmount.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.updateStarGiftPrice#edbe6ccb: field resell_amount: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *PaymentsUpdateStarGiftPriceRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode payments.updateStarGiftPrice#edbe6ccb to nil")
	}
	if err := b.ConsumeID(PaymentsUpdateStarGiftPriceRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.updateStarGiftPrice#edbe6ccb: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *PaymentsUpdateStarGiftPriceRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode payments.updateStarGiftPrice#edbe6ccb to nil")
	}
	{
		value, err := DecodeInputSavedStarGift(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.updateStarGiftPrice#edbe6ccb: field stargift: %w", err)
		}
		u.Stargift = value
	}
	{
		value, err := DecodeStarsAmount(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.updateStarGiftPrice#edbe6ccb: field resell_amount: %w", err)
		}
		u.ResellAmount = value
	}
	return nil
}

// GetStargift returns value of Stargift field.
func (u *PaymentsUpdateStarGiftPriceRequest) GetStargift() (value InputSavedStarGiftClass) {
	if u == nil {
		return
	}
	return u.Stargift
}

// GetResellAmount returns value of ResellAmount field.
func (u *PaymentsUpdateStarGiftPriceRequest) GetResellAmount() (value StarsAmountClass) {
	if u == nil {
		return
	}
	return u.ResellAmount
}

// PaymentsUpdateStarGiftPrice invokes method payments.updateStarGiftPrice#edbe6ccb returning error if any.
// A collectible gift we own »¹ can be put up for sale on the gift marketplace »²
// with this method, see here »³ for more info.
//
// Links:
//  1. https://core.telegram.org/api/gifts#collectible-gifts
//  2. https://telegram.org/blog/gift-marketplace-and-more
//  3. https://core.telegram.org/api/gifts#reselling-collectible-gifts
//
// Possible errors:
//
//	400 SAVED_ID_EMPTY: The passed inputSavedStarGiftChat.saved_id is empty.
//	400 STARGIFT_NOT_FOUND: The specified gift was not found.
//
// See https://core.telegram.org/method/payments.updateStarGiftPrice for reference.
func (c *Client) PaymentsUpdateStarGiftPrice(ctx context.Context, request *PaymentsUpdateStarGiftPriceRequest) (UpdatesClass, error) {
	var result UpdatesBox

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