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

// EmojiURL represents TL type `emojiURL#a575739d`.
// An HTTP URL which can be used to automatically log in into translation platform and
// suggest new emoji replacements. The URL will be valid for 30 seconds after generation
//
// See https://core.telegram.org/constructor/emojiURL for reference.
type EmojiURL struct {
	// An HTTP URL which can be used to automatically log in into translation platform and
	// suggest new emoji replacements. The URL will be valid for 30 seconds after generation
	URL string
}

// EmojiURLTypeID is TL type id of EmojiURL.
const EmojiURLTypeID = 0xa575739d

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

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

	return true
}

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

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

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

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

// TypeInfo returns info about TL type.
func (e *EmojiURL) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "emojiURL",
		ID:   EmojiURLTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *EmojiURL) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiURL#a575739d as nil")
	}
	b.PutID(EmojiURLTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *EmojiURL) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiURL#a575739d as nil")
	}
	b.PutString(e.URL)
	return nil
}

// Decode implements bin.Decoder.
func (e *EmojiURL) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiURL#a575739d to nil")
	}
	if err := b.ConsumeID(EmojiURLTypeID); err != nil {
		return fmt.Errorf("unable to decode emojiURL#a575739d: %w", err)
	}
	return e.DecodeBare(b)
}

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

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