// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// EmojiStatus represents TL type `emojiStatus#3a054910`.
type EmojiStatus struct {
	// Type of the emoji status
	Type EmojiStatusTypeClass
	// Point in time (Unix timestamp) when the status will expire; 0 if never
	ExpirationDate int32
}

// EmojiStatusTypeID is TL type id of EmojiStatus.
const EmojiStatusTypeID = 0x3a054910

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

func (e *EmojiStatus) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Type == nil) {
		return false
	}
	if !(e.ExpirationDate == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (e *EmojiStatus) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "emojiStatus",
		ID:   EmojiStatusTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Type",
			SchemaName: "type",
		},
		{
			Name:       "ExpirationDate",
			SchemaName: "expiration_date",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *EmojiStatus) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiStatus#3a054910 as nil")
	}
	b.PutID(EmojiStatusTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *EmojiStatus) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiStatus#3a054910 as nil")
	}
	if e.Type == nil {
		return fmt.Errorf("unable to encode emojiStatus#3a054910: field type is nil")
	}
	if err := e.Type.Encode(b); err != nil {
		return fmt.Errorf("unable to encode emojiStatus#3a054910: field type: %w", err)
	}
	b.PutInt32(e.ExpirationDate)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (e *EmojiStatus) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiStatus#3a054910 to nil")
	}
	{
		value, err := DecodeEmojiStatusType(b)
		if err != nil {
			return fmt.Errorf("unable to decode emojiStatus#3a054910: field type: %w", err)
		}
		e.Type = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode emojiStatus#3a054910: field expiration_date: %w", err)
		}
		e.ExpirationDate = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (e *EmojiStatus) EncodeTDLibJSON(b tdjson.Encoder) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiStatus#3a054910 as nil")
	}
	b.ObjStart()
	b.PutID("emojiStatus")
	b.Comma()
	b.FieldStart("type")
	if e.Type == nil {
		return fmt.Errorf("unable to encode emojiStatus#3a054910: field type is nil")
	}
	if err := e.Type.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode emojiStatus#3a054910: field type: %w", err)
	}
	b.Comma()
	b.FieldStart("expiration_date")
	b.PutInt32(e.ExpirationDate)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (e *EmojiStatus) DecodeTDLibJSON(b tdjson.Decoder) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiStatus#3a054910 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("emojiStatus"); err != nil {
				return fmt.Errorf("unable to decode emojiStatus#3a054910: %w", err)
			}
		case "type":
			value, err := DecodeTDLibJSONEmojiStatusType(b)
			if err != nil {
				return fmt.Errorf("unable to decode emojiStatus#3a054910: field type: %w", err)
			}
			e.Type = value
		case "expiration_date":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode emojiStatus#3a054910: field expiration_date: %w", err)
			}
			e.ExpirationDate = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetType returns value of Type field.
func (e *EmojiStatus) GetType() (value EmojiStatusTypeClass) {
	if e == nil {
		return
	}
	return e.Type
}

// GetExpirationDate returns value of ExpirationDate field.
func (e *EmojiStatus) GetExpirationDate() (value int32) {
	if e == nil {
		return
	}
	return e.ExpirationDate
}
