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

// SearchMessagesChatTypeFilterPrivate represents TL type `searchMessagesChatTypeFilterPrivate#45b152cf`.
type SearchMessagesChatTypeFilterPrivate struct {
}

// SearchMessagesChatTypeFilterPrivateTypeID is TL type id of SearchMessagesChatTypeFilterPrivate.
const SearchMessagesChatTypeFilterPrivateTypeID = 0x45b152cf

// construct implements constructor of SearchMessagesChatTypeFilterClass.
func (s SearchMessagesChatTypeFilterPrivate) construct() SearchMessagesChatTypeFilterClass { return &s }

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

	_ SearchMessagesChatTypeFilterClass = &SearchMessagesChatTypeFilterPrivate{}
)

func (s *SearchMessagesChatTypeFilterPrivate) Zero() bool {
	if s == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SearchMessagesChatTypeFilterPrivate) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterPrivate#45b152cf as nil")
	}
	b.PutID(SearchMessagesChatTypeFilterPrivateTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SearchMessagesChatTypeFilterPrivate) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterPrivate#45b152cf as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SearchMessagesChatTypeFilterPrivate) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterPrivate#45b152cf to nil")
	}
	if err := b.ConsumeID(SearchMessagesChatTypeFilterPrivateTypeID); err != nil {
		return fmt.Errorf("unable to decode searchMessagesChatTypeFilterPrivate#45b152cf: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SearchMessagesChatTypeFilterPrivate) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterPrivate#45b152cf to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SearchMessagesChatTypeFilterPrivate) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterPrivate#45b152cf as nil")
	}
	b.ObjStart()
	b.PutID("searchMessagesChatTypeFilterPrivate")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SearchMessagesChatTypeFilterPrivate) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterPrivate#45b152cf to nil")
	}

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

// SearchMessagesChatTypeFilterGroup represents TL type `searchMessagesChatTypeFilterGroup#853fa71a`.
type SearchMessagesChatTypeFilterGroup struct {
}

// SearchMessagesChatTypeFilterGroupTypeID is TL type id of SearchMessagesChatTypeFilterGroup.
const SearchMessagesChatTypeFilterGroupTypeID = 0x853fa71a

// construct implements constructor of SearchMessagesChatTypeFilterClass.
func (s SearchMessagesChatTypeFilterGroup) construct() SearchMessagesChatTypeFilterClass { return &s }

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

	_ SearchMessagesChatTypeFilterClass = &SearchMessagesChatTypeFilterGroup{}
)

func (s *SearchMessagesChatTypeFilterGroup) Zero() bool {
	if s == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SearchMessagesChatTypeFilterGroup) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterGroup#853fa71a as nil")
	}
	b.PutID(SearchMessagesChatTypeFilterGroupTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SearchMessagesChatTypeFilterGroup) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterGroup#853fa71a as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SearchMessagesChatTypeFilterGroup) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterGroup#853fa71a to nil")
	}
	if err := b.ConsumeID(SearchMessagesChatTypeFilterGroupTypeID); err != nil {
		return fmt.Errorf("unable to decode searchMessagesChatTypeFilterGroup#853fa71a: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SearchMessagesChatTypeFilterGroup) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterGroup#853fa71a to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SearchMessagesChatTypeFilterGroup) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterGroup#853fa71a as nil")
	}
	b.ObjStart()
	b.PutID("searchMessagesChatTypeFilterGroup")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SearchMessagesChatTypeFilterGroup) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterGroup#853fa71a to nil")
	}

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

// SearchMessagesChatTypeFilterChannel represents TL type `searchMessagesChatTypeFilterChannel#d1e4b6d5`.
type SearchMessagesChatTypeFilterChannel struct {
}

// SearchMessagesChatTypeFilterChannelTypeID is TL type id of SearchMessagesChatTypeFilterChannel.
const SearchMessagesChatTypeFilterChannelTypeID = 0xd1e4b6d5

// construct implements constructor of SearchMessagesChatTypeFilterClass.
func (s SearchMessagesChatTypeFilterChannel) construct() SearchMessagesChatTypeFilterClass { return &s }

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

	_ SearchMessagesChatTypeFilterClass = &SearchMessagesChatTypeFilterChannel{}
)

func (s *SearchMessagesChatTypeFilterChannel) Zero() bool {
	if s == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SearchMessagesChatTypeFilterChannel) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterChannel#d1e4b6d5 as nil")
	}
	b.PutID(SearchMessagesChatTypeFilterChannelTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SearchMessagesChatTypeFilterChannel) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode searchMessagesChatTypeFilterChannel#d1e4b6d5 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SearchMessagesChatTypeFilterChannel) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterChannel#d1e4b6d5 to nil")
	}
	if err := b.ConsumeID(SearchMessagesChatTypeFilterChannelTypeID); err != nil {
		return fmt.Errorf("unable to decode searchMessagesChatTypeFilterChannel#d1e4b6d5: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SearchMessagesChatTypeFilterChannel) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterChannel#d1e4b6d5 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SearchMessagesChatTypeFilterChannel) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode searchMessagesChatTypeFilterChannel#d1e4b6d5 to nil")
	}

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

// SearchMessagesChatTypeFilterClassName is schema name of SearchMessagesChatTypeFilterClass.
const SearchMessagesChatTypeFilterClassName = "SearchMessagesChatTypeFilter"

// SearchMessagesChatTypeFilterClass represents SearchMessagesChatTypeFilter generic type.
//
// Example:
//
//	g, err := tdapi.DecodeSearchMessagesChatTypeFilter(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.SearchMessagesChatTypeFilterPrivate: // searchMessagesChatTypeFilterPrivate#45b152cf
//	case *tdapi.SearchMessagesChatTypeFilterGroup: // searchMessagesChatTypeFilterGroup#853fa71a
//	case *tdapi.SearchMessagesChatTypeFilterChannel: // searchMessagesChatTypeFilterChannel#d1e4b6d5
//	default: panic(v)
//	}
type SearchMessagesChatTypeFilterClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() SearchMessagesChatTypeFilterClass

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

// DecodeSearchMessagesChatTypeFilter implements binary de-serialization for SearchMessagesChatTypeFilterClass.
func DecodeSearchMessagesChatTypeFilter(buf *bin.Buffer) (SearchMessagesChatTypeFilterClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case SearchMessagesChatTypeFilterPrivateTypeID:
		// Decoding searchMessagesChatTypeFilterPrivate#45b152cf.
		v := SearchMessagesChatTypeFilterPrivate{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", err)
		}
		return &v, nil
	case SearchMessagesChatTypeFilterGroupTypeID:
		// Decoding searchMessagesChatTypeFilterGroup#853fa71a.
		v := SearchMessagesChatTypeFilterGroup{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", err)
		}
		return &v, nil
	case SearchMessagesChatTypeFilterChannelTypeID:
		// Decoding searchMessagesChatTypeFilterChannel#d1e4b6d5.
		v := SearchMessagesChatTypeFilterChannel{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONSearchMessagesChatTypeFilter implements binary de-serialization for SearchMessagesChatTypeFilterClass.
func DecodeTDLibJSONSearchMessagesChatTypeFilter(buf tdjson.Decoder) (SearchMessagesChatTypeFilterClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "searchMessagesChatTypeFilterPrivate":
		// Decoding searchMessagesChatTypeFilterPrivate#45b152cf.
		v := SearchMessagesChatTypeFilterPrivate{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", err)
		}
		return &v, nil
	case "searchMessagesChatTypeFilterGroup":
		// Decoding searchMessagesChatTypeFilterGroup#853fa71a.
		v := SearchMessagesChatTypeFilterGroup{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", err)
		}
		return &v, nil
	case "searchMessagesChatTypeFilterChannel":
		// Decoding searchMessagesChatTypeFilterChannel#d1e4b6d5.
		v := SearchMessagesChatTypeFilterChannel{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode SearchMessagesChatTypeFilterClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// SearchMessagesChatTypeFilter boxes the SearchMessagesChatTypeFilterClass providing a helper.
type SearchMessagesChatTypeFilterBox struct {
	SearchMessagesChatTypeFilter SearchMessagesChatTypeFilterClass
}

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

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

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

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