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

// PaymentsStarsRevenueWithdrawalURL represents TL type `payments.starsRevenueWithdrawalUrl#1dab80b7`.
// Contains the URL to use to withdraw Telegram Star revenue¹.
//
// Links:
//  1. https://core.telegram.org/api/stars#withdrawing-revenue
//
// See https://core.telegram.org/constructor/payments.starsRevenueWithdrawalUrl for reference.
type PaymentsStarsRevenueWithdrawalURL struct {
	// Contains the URL to use to withdraw Telegram Star revenue¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars#withdrawing-revenue
	URL string
}

// PaymentsStarsRevenueWithdrawalURLTypeID is TL type id of PaymentsStarsRevenueWithdrawalURL.
const PaymentsStarsRevenueWithdrawalURLTypeID = 0x1dab80b7

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

func (s *PaymentsStarsRevenueWithdrawalURL) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.URL == "") {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsStarsRevenueWithdrawalURL from given interface.
func (s *PaymentsStarsRevenueWithdrawalURL) FillFrom(from interface {
	GetURL() (value string)
}) {
	s.URL = from.GetURL()
}

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

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

// TypeInfo returns info about TL type.
func (s *PaymentsStarsRevenueWithdrawalURL) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.starsRevenueWithdrawalUrl",
		ID:   PaymentsStarsRevenueWithdrawalURLTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *PaymentsStarsRevenueWithdrawalURL) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode payments.starsRevenueWithdrawalUrl#1dab80b7 as nil")
	}
	b.PutID(PaymentsStarsRevenueWithdrawalURLTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *PaymentsStarsRevenueWithdrawalURL) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode payments.starsRevenueWithdrawalUrl#1dab80b7 as nil")
	}
	b.PutString(s.URL)
	return nil
}

// Decode implements bin.Decoder.
func (s *PaymentsStarsRevenueWithdrawalURL) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode payments.starsRevenueWithdrawalUrl#1dab80b7 to nil")
	}
	if err := b.ConsumeID(PaymentsStarsRevenueWithdrawalURLTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.starsRevenueWithdrawalUrl#1dab80b7: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *PaymentsStarsRevenueWithdrawalURL) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode payments.starsRevenueWithdrawalUrl#1dab80b7 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode payments.starsRevenueWithdrawalUrl#1dab80b7: field url: %w", err)
		}
		s.URL = value
	}
	return nil
}

// GetURL returns value of URL field.
func (s *PaymentsStarsRevenueWithdrawalURL) GetURL() (value string) {
	if s == nil {
		return
	}
	return s.URL
}
