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

// UserTypeRegular represents TL type `userTypeRegular#dc51699b`.
type UserTypeRegular struct {
}

// UserTypeRegularTypeID is TL type id of UserTypeRegular.
const UserTypeRegularTypeID = 0xdc51699b

// construct implements constructor of UserTypeClass.
func (u UserTypeRegular) construct() UserTypeClass { return &u }

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

	_ UserTypeClass = &UserTypeRegular{}
)

func (u *UserTypeRegular) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserTypeRegular) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userTypeRegular",
		ID:   UserTypeRegularTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserTypeRegular) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeRegular#dc51699b as nil")
	}
	b.PutID(UserTypeRegularTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserTypeRegular) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeRegular#dc51699b as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (u *UserTypeRegular) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeRegular#dc51699b to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserTypeRegular) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeRegular#dc51699b as nil")
	}
	b.ObjStart()
	b.PutID("userTypeRegular")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserTypeRegular) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeRegular#dc51699b to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userTypeRegular"); err != nil {
				return fmt.Errorf("unable to decode userTypeRegular#dc51699b: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserTypeDeleted represents TL type `userTypeDeleted#94403d24`.
type UserTypeDeleted struct {
}

// UserTypeDeletedTypeID is TL type id of UserTypeDeleted.
const UserTypeDeletedTypeID = 0x94403d24

// construct implements constructor of UserTypeClass.
func (u UserTypeDeleted) construct() UserTypeClass { return &u }

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

	_ UserTypeClass = &UserTypeDeleted{}
)

func (u *UserTypeDeleted) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserTypeDeleted) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userTypeDeleted",
		ID:   UserTypeDeletedTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserTypeDeleted) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeDeleted#94403d24 as nil")
	}
	b.PutID(UserTypeDeletedTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserTypeDeleted) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeDeleted#94403d24 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *UserTypeDeleted) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeDeleted#94403d24 to nil")
	}
	if err := b.ConsumeID(UserTypeDeletedTypeID); err != nil {
		return fmt.Errorf("unable to decode userTypeDeleted#94403d24: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserTypeDeleted) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeDeleted#94403d24 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserTypeDeleted) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeDeleted#94403d24 as nil")
	}
	b.ObjStart()
	b.PutID("userTypeDeleted")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserTypeDeleted) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeDeleted#94403d24 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userTypeDeleted"); err != nil {
				return fmt.Errorf("unable to decode userTypeDeleted#94403d24: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserTypeBot represents TL type `userTypeBot#8ba3cc26`.
type UserTypeBot struct {
	// True, if the bot is owned by the current user and can be edited using the methods
	// toggleBotUsernameIsActive, reorderBotActiveUsernames, setBotProfilePhoto, setBotName,
	// setBotInfoDescription, and setBotInfoShortDescription
	CanBeEdited bool
	// True, if the bot can be invited to basic group and supergroup chats
	CanJoinGroups bool
	// True, if the bot can read all messages in basic group or supergroup chats and not just
	// those addressed to the bot. In private and channel chats a bot can always read all
	// messages
	CanReadAllGroupMessages bool
	// True, if the bot has the main Web App
	HasMainWebApp bool
	// True, if the bot supports inline queries
	IsInline bool
	// Placeholder for inline queries (displayed on the application input field)
	InlineQueryPlaceholder string
	// True, if the location of the user is expected to be sent with every inline query to
	// this bot
	NeedLocation bool
	// True, if the bot supports connection to Telegram Business accounts
	CanConnectToBusiness bool
	// True, if the bot can be added to attachment or side menu
	CanBeAddedToAttachmentMenu bool
	// The number of recently active users of the bot
	ActiveUserCount int32
}

// UserTypeBotTypeID is TL type id of UserTypeBot.
const UserTypeBotTypeID = 0x8ba3cc26

// construct implements constructor of UserTypeClass.
func (u UserTypeBot) construct() UserTypeClass { return &u }

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

	_ UserTypeClass = &UserTypeBot{}
)

func (u *UserTypeBot) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.CanBeEdited == false) {
		return false
	}
	if !(u.CanJoinGroups == false) {
		return false
	}
	if !(u.CanReadAllGroupMessages == false) {
		return false
	}
	if !(u.HasMainWebApp == false) {
		return false
	}
	if !(u.IsInline == false) {
		return false
	}
	if !(u.InlineQueryPlaceholder == "") {
		return false
	}
	if !(u.NeedLocation == false) {
		return false
	}
	if !(u.CanConnectToBusiness == false) {
		return false
	}
	if !(u.CanBeAddedToAttachmentMenu == false) {
		return false
	}
	if !(u.ActiveUserCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserTypeBot) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userTypeBot",
		ID:   UserTypeBotTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "CanBeEdited",
			SchemaName: "can_be_edited",
		},
		{
			Name:       "CanJoinGroups",
			SchemaName: "can_join_groups",
		},
		{
			Name:       "CanReadAllGroupMessages",
			SchemaName: "can_read_all_group_messages",
		},
		{
			Name:       "HasMainWebApp",
			SchemaName: "has_main_web_app",
		},
		{
			Name:       "IsInline",
			SchemaName: "is_inline",
		},
		{
			Name:       "InlineQueryPlaceholder",
			SchemaName: "inline_query_placeholder",
		},
		{
			Name:       "NeedLocation",
			SchemaName: "need_location",
		},
		{
			Name:       "CanConnectToBusiness",
			SchemaName: "can_connect_to_business",
		},
		{
			Name:       "CanBeAddedToAttachmentMenu",
			SchemaName: "can_be_added_to_attachment_menu",
		},
		{
			Name:       "ActiveUserCount",
			SchemaName: "active_user_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserTypeBot) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeBot#8ba3cc26 as nil")
	}
	b.PutID(UserTypeBotTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserTypeBot) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeBot#8ba3cc26 as nil")
	}
	b.PutBool(u.CanBeEdited)
	b.PutBool(u.CanJoinGroups)
	b.PutBool(u.CanReadAllGroupMessages)
	b.PutBool(u.HasMainWebApp)
	b.PutBool(u.IsInline)
	b.PutString(u.InlineQueryPlaceholder)
	b.PutBool(u.NeedLocation)
	b.PutBool(u.CanConnectToBusiness)
	b.PutBool(u.CanBeAddedToAttachmentMenu)
	b.PutInt32(u.ActiveUserCount)
	return nil
}

// Decode implements bin.Decoder.
func (u *UserTypeBot) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeBot#8ba3cc26 to nil")
	}
	if err := b.ConsumeID(UserTypeBotTypeID); err != nil {
		return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UserTypeBot) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeBot#8ba3cc26 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_be_edited: %w", err)
		}
		u.CanBeEdited = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_join_groups: %w", err)
		}
		u.CanJoinGroups = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_read_all_group_messages: %w", err)
		}
		u.CanReadAllGroupMessages = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field has_main_web_app: %w", err)
		}
		u.HasMainWebApp = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field is_inline: %w", err)
		}
		u.IsInline = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field inline_query_placeholder: %w", err)
		}
		u.InlineQueryPlaceholder = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field need_location: %w", err)
		}
		u.NeedLocation = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_connect_to_business: %w", err)
		}
		u.CanConnectToBusiness = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_be_added_to_attachment_menu: %w", err)
		}
		u.CanBeAddedToAttachmentMenu = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field active_user_count: %w", err)
		}
		u.ActiveUserCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserTypeBot) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeBot#8ba3cc26 as nil")
	}
	b.ObjStart()
	b.PutID("userTypeBot")
	b.Comma()
	b.FieldStart("can_be_edited")
	b.PutBool(u.CanBeEdited)
	b.Comma()
	b.FieldStart("can_join_groups")
	b.PutBool(u.CanJoinGroups)
	b.Comma()
	b.FieldStart("can_read_all_group_messages")
	b.PutBool(u.CanReadAllGroupMessages)
	b.Comma()
	b.FieldStart("has_main_web_app")
	b.PutBool(u.HasMainWebApp)
	b.Comma()
	b.FieldStart("is_inline")
	b.PutBool(u.IsInline)
	b.Comma()
	b.FieldStart("inline_query_placeholder")
	b.PutString(u.InlineQueryPlaceholder)
	b.Comma()
	b.FieldStart("need_location")
	b.PutBool(u.NeedLocation)
	b.Comma()
	b.FieldStart("can_connect_to_business")
	b.PutBool(u.CanConnectToBusiness)
	b.Comma()
	b.FieldStart("can_be_added_to_attachment_menu")
	b.PutBool(u.CanBeAddedToAttachmentMenu)
	b.Comma()
	b.FieldStart("active_user_count")
	b.PutInt32(u.ActiveUserCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserTypeBot) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeBot#8ba3cc26 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userTypeBot"); err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: %w", err)
			}
		case "can_be_edited":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_be_edited: %w", err)
			}
			u.CanBeEdited = value
		case "can_join_groups":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_join_groups: %w", err)
			}
			u.CanJoinGroups = value
		case "can_read_all_group_messages":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_read_all_group_messages: %w", err)
			}
			u.CanReadAllGroupMessages = value
		case "has_main_web_app":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field has_main_web_app: %w", err)
			}
			u.HasMainWebApp = value
		case "is_inline":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field is_inline: %w", err)
			}
			u.IsInline = value
		case "inline_query_placeholder":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field inline_query_placeholder: %w", err)
			}
			u.InlineQueryPlaceholder = value
		case "need_location":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field need_location: %w", err)
			}
			u.NeedLocation = value
		case "can_connect_to_business":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_connect_to_business: %w", err)
			}
			u.CanConnectToBusiness = value
		case "can_be_added_to_attachment_menu":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field can_be_added_to_attachment_menu: %w", err)
			}
			u.CanBeAddedToAttachmentMenu = value
		case "active_user_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode userTypeBot#8ba3cc26: field active_user_count: %w", err)
			}
			u.ActiveUserCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetCanBeEdited returns value of CanBeEdited field.
func (u *UserTypeBot) GetCanBeEdited() (value bool) {
	if u == nil {
		return
	}
	return u.CanBeEdited
}

// GetCanJoinGroups returns value of CanJoinGroups field.
func (u *UserTypeBot) GetCanJoinGroups() (value bool) {
	if u == nil {
		return
	}
	return u.CanJoinGroups
}

// GetCanReadAllGroupMessages returns value of CanReadAllGroupMessages field.
func (u *UserTypeBot) GetCanReadAllGroupMessages() (value bool) {
	if u == nil {
		return
	}
	return u.CanReadAllGroupMessages
}

// GetHasMainWebApp returns value of HasMainWebApp field.
func (u *UserTypeBot) GetHasMainWebApp() (value bool) {
	if u == nil {
		return
	}
	return u.HasMainWebApp
}

// GetIsInline returns value of IsInline field.
func (u *UserTypeBot) GetIsInline() (value bool) {
	if u == nil {
		return
	}
	return u.IsInline
}

// GetInlineQueryPlaceholder returns value of InlineQueryPlaceholder field.
func (u *UserTypeBot) GetInlineQueryPlaceholder() (value string) {
	if u == nil {
		return
	}
	return u.InlineQueryPlaceholder
}

// GetNeedLocation returns value of NeedLocation field.
func (u *UserTypeBot) GetNeedLocation() (value bool) {
	if u == nil {
		return
	}
	return u.NeedLocation
}

// GetCanConnectToBusiness returns value of CanConnectToBusiness field.
func (u *UserTypeBot) GetCanConnectToBusiness() (value bool) {
	if u == nil {
		return
	}
	return u.CanConnectToBusiness
}

// GetCanBeAddedToAttachmentMenu returns value of CanBeAddedToAttachmentMenu field.
func (u *UserTypeBot) GetCanBeAddedToAttachmentMenu() (value bool) {
	if u == nil {
		return
	}
	return u.CanBeAddedToAttachmentMenu
}

// GetActiveUserCount returns value of ActiveUserCount field.
func (u *UserTypeBot) GetActiveUserCount() (value int32) {
	if u == nil {
		return
	}
	return u.ActiveUserCount
}

// UserTypeUnknown represents TL type `userTypeUnknown#d4d0613d`.
type UserTypeUnknown struct {
}

// UserTypeUnknownTypeID is TL type id of UserTypeUnknown.
const UserTypeUnknownTypeID = 0xd4d0613d

// construct implements constructor of UserTypeClass.
func (u UserTypeUnknown) construct() UserTypeClass { return &u }

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

	_ UserTypeClass = &UserTypeUnknown{}
)

func (u *UserTypeUnknown) Zero() bool {
	if u == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UserTypeUnknown) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "userTypeUnknown",
		ID:   UserTypeUnknownTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (u *UserTypeUnknown) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeUnknown#d4d0613d as nil")
	}
	b.PutID(UserTypeUnknownTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UserTypeUnknown) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeUnknown#d4d0613d as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (u *UserTypeUnknown) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeUnknown#d4d0613d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UserTypeUnknown) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode userTypeUnknown#d4d0613d as nil")
	}
	b.ObjStart()
	b.PutID("userTypeUnknown")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UserTypeUnknown) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode userTypeUnknown#d4d0613d to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("userTypeUnknown"); err != nil {
				return fmt.Errorf("unable to decode userTypeUnknown#d4d0613d: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// UserTypeClassName is schema name of UserTypeClass.
const UserTypeClassName = "UserType"

// UserTypeClass represents UserType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeUserType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.UserTypeRegular: // userTypeRegular#dc51699b
//	case *tdapi.UserTypeDeleted: // userTypeDeleted#94403d24
//	case *tdapi.UserTypeBot: // userTypeBot#8ba3cc26
//	case *tdapi.UserTypeUnknown: // userTypeUnknown#d4d0613d
//	default: panic(v)
//	}
type UserTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UserTypeClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeUserType implements binary de-serialization for UserTypeClass.
func DecodeUserType(buf *bin.Buffer) (UserTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case UserTypeRegularTypeID:
		// Decoding userTypeRegular#dc51699b.
		v := UserTypeRegular{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	case UserTypeDeletedTypeID:
		// Decoding userTypeDeleted#94403d24.
		v := UserTypeDeleted{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	case UserTypeBotTypeID:
		// Decoding userTypeBot#8ba3cc26.
		v := UserTypeBot{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	case UserTypeUnknownTypeID:
		// Decoding userTypeUnknown#d4d0613d.
		v := UserTypeUnknown{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode UserTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONUserType implements binary de-serialization for UserTypeClass.
func DecodeTDLibJSONUserType(buf tdjson.Decoder) (UserTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "userTypeRegular":
		// Decoding userTypeRegular#dc51699b.
		v := UserTypeRegular{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	case "userTypeDeleted":
		// Decoding userTypeDeleted#94403d24.
		v := UserTypeDeleted{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	case "userTypeBot":
		// Decoding userTypeBot#8ba3cc26.
		v := UserTypeBot{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	case "userTypeUnknown":
		// Decoding userTypeUnknown#d4d0613d.
		v := UserTypeUnknown{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode UserTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode UserTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// UserType boxes the UserTypeClass providing a helper.
type UserTypeBox struct {
	UserType UserTypeClass
}

// Decode implements bin.Decoder for UserTypeBox.
func (b *UserTypeBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode UserTypeBox to nil")
	}
	v, err := DecodeUserType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.UserType = v
	return nil
}

// Encode implements bin.Encode for UserTypeBox.
func (b *UserTypeBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.UserType == nil {
		return fmt.Errorf("unable to encode UserTypeClass as nil")
	}
	return b.UserType.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for UserTypeBox.
func (b *UserTypeBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode UserTypeBox to nil")
	}
	v, err := DecodeTDLibJSONUserType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.UserType = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for UserTypeBox.
func (b *UserTypeBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.UserType == nil {
		return fmt.Errorf("unable to encode UserTypeClass as nil")
	}
	return b.UserType.EncodeTDLibJSON(buf)
}
