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

// PaymentsStarGiftWithdrawalURL represents TL type `payments.starGiftWithdrawalUrl#84aa3a9c`.
// A URL that can be used to import the exported NFT on Fragment.
//
// See https://core.telegram.org/constructor/payments.starGiftWithdrawalUrl for reference.
type PaymentsStarGiftWithdrawalURL struct {
	// The URL to open.
	URL string
}

// PaymentsStarGiftWithdrawalURLTypeID is TL type id of PaymentsStarGiftWithdrawalURL.
const PaymentsStarGiftWithdrawalURLTypeID = 0x84aa3a9c

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

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

	return true
}

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

// FillFrom fills PaymentsStarGiftWithdrawalURL from given interface.
func (s *PaymentsStarGiftWithdrawalURL) 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 (*PaymentsStarGiftWithdrawalURL) TypeID() uint32 {
	return PaymentsStarGiftWithdrawalURLTypeID
}

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

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

// Encode implements bin.Encoder.
func (s *PaymentsStarGiftWithdrawalURL) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode payments.starGiftWithdrawalUrl#84aa3a9c as nil")
	}
	b.PutID(PaymentsStarGiftWithdrawalURLTypeID)
	return s.EncodeBare(b)
}

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

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

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

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