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

// CanSendMessageToUserResultOk represents TL type `canSendMessageToUserResultOk#5b3ad802`.
type CanSendMessageToUserResultOk struct {
}

// CanSendMessageToUserResultOkTypeID is TL type id of CanSendMessageToUserResultOk.
const CanSendMessageToUserResultOkTypeID = 0x5b3ad802

// construct implements constructor of CanSendMessageToUserResultClass.
func (c CanSendMessageToUserResultOk) construct() CanSendMessageToUserResultClass { return &c }

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

	_ CanSendMessageToUserResultClass = &CanSendMessageToUserResultOk{}
)

func (c *CanSendMessageToUserResultOk) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CanSendMessageToUserResultOk) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultOk#5b3ad802 as nil")
	}
	b.PutID(CanSendMessageToUserResultOkTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanSendMessageToUserResultOk) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultOk#5b3ad802 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CanSendMessageToUserResultOk) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultOk#5b3ad802 to nil")
	}
	if err := b.ConsumeID(CanSendMessageToUserResultOkTypeID); err != nil {
		return fmt.Errorf("unable to decode canSendMessageToUserResultOk#5b3ad802: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanSendMessageToUserResultOk) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultOk#5b3ad802 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanSendMessageToUserResultOk) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultOk#5b3ad802 as nil")
	}
	b.ObjStart()
	b.PutID("canSendMessageToUserResultOk")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanSendMessageToUserResultOk) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultOk#5b3ad802 to nil")
	}

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

// CanSendMessageToUserResultUserHasPaidMessages represents TL type `canSendMessageToUserResultUserHasPaidMessages#afbe3ace`.
type CanSendMessageToUserResultUserHasPaidMessages struct {
	// Number of Telegram Stars that must be paid by the current user for each sent message
	// to the user
	OutgoingPaidMessageStarCount int64
}

// CanSendMessageToUserResultUserHasPaidMessagesTypeID is TL type id of CanSendMessageToUserResultUserHasPaidMessages.
const CanSendMessageToUserResultUserHasPaidMessagesTypeID = 0xafbe3ace

// construct implements constructor of CanSendMessageToUserResultClass.
func (c CanSendMessageToUserResultUserHasPaidMessages) construct() CanSendMessageToUserResultClass {
	return &c
}

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

	_ CanSendMessageToUserResultClass = &CanSendMessageToUserResultUserHasPaidMessages{}
)

func (c *CanSendMessageToUserResultUserHasPaidMessages) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.OutgoingPaidMessageStarCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanSendMessageToUserResultUserHasPaidMessages) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canSendMessageToUserResultUserHasPaidMessages",
		ID:   CanSendMessageToUserResultUserHasPaidMessagesTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "OutgoingPaidMessageStarCount",
			SchemaName: "outgoing_paid_message_star_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanSendMessageToUserResultUserHasPaidMessages) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserHasPaidMessages#afbe3ace as nil")
	}
	b.PutID(CanSendMessageToUserResultUserHasPaidMessagesTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanSendMessageToUserResultUserHasPaidMessages) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserHasPaidMessages#afbe3ace as nil")
	}
	b.PutInt53(c.OutgoingPaidMessageStarCount)
	return nil
}

// Decode implements bin.Decoder.
func (c *CanSendMessageToUserResultUserHasPaidMessages) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserHasPaidMessages#afbe3ace to nil")
	}
	if err := b.ConsumeID(CanSendMessageToUserResultUserHasPaidMessagesTypeID); err != nil {
		return fmt.Errorf("unable to decode canSendMessageToUserResultUserHasPaidMessages#afbe3ace: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanSendMessageToUserResultUserHasPaidMessages) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserHasPaidMessages#afbe3ace to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode canSendMessageToUserResultUserHasPaidMessages#afbe3ace: field outgoing_paid_message_star_count: %w", err)
		}
		c.OutgoingPaidMessageStarCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanSendMessageToUserResultUserHasPaidMessages) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserHasPaidMessages#afbe3ace as nil")
	}
	b.ObjStart()
	b.PutID("canSendMessageToUserResultUserHasPaidMessages")
	b.Comma()
	b.FieldStart("outgoing_paid_message_star_count")
	b.PutInt53(c.OutgoingPaidMessageStarCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanSendMessageToUserResultUserHasPaidMessages) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserHasPaidMessages#afbe3ace to nil")
	}

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

// GetOutgoingPaidMessageStarCount returns value of OutgoingPaidMessageStarCount field.
func (c *CanSendMessageToUserResultUserHasPaidMessages) GetOutgoingPaidMessageStarCount() (value int64) {
	if c == nil {
		return
	}
	return c.OutgoingPaidMessageStarCount
}

// CanSendMessageToUserResultUserIsDeleted represents TL type `canSendMessageToUserResultUserIsDeleted#8c172661`.
type CanSendMessageToUserResultUserIsDeleted struct {
}

// CanSendMessageToUserResultUserIsDeletedTypeID is TL type id of CanSendMessageToUserResultUserIsDeleted.
const CanSendMessageToUserResultUserIsDeletedTypeID = 0x8c172661

// construct implements constructor of CanSendMessageToUserResultClass.
func (c CanSendMessageToUserResultUserIsDeleted) construct() CanSendMessageToUserResultClass {
	return &c
}

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

	_ CanSendMessageToUserResultClass = &CanSendMessageToUserResultUserIsDeleted{}
)

func (c *CanSendMessageToUserResultUserIsDeleted) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CanSendMessageToUserResultUserIsDeleted) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserIsDeleted#8c172661 as nil")
	}
	b.PutID(CanSendMessageToUserResultUserIsDeletedTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanSendMessageToUserResultUserIsDeleted) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserIsDeleted#8c172661 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CanSendMessageToUserResultUserIsDeleted) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserIsDeleted#8c172661 to nil")
	}
	if err := b.ConsumeID(CanSendMessageToUserResultUserIsDeletedTypeID); err != nil {
		return fmt.Errorf("unable to decode canSendMessageToUserResultUserIsDeleted#8c172661: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanSendMessageToUserResultUserIsDeleted) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserIsDeleted#8c172661 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanSendMessageToUserResultUserIsDeleted) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserIsDeleted#8c172661 as nil")
	}
	b.ObjStart()
	b.PutID("canSendMessageToUserResultUserIsDeleted")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanSendMessageToUserResultUserIsDeleted) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserIsDeleted#8c172661 to nil")
	}

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

// CanSendMessageToUserResultUserRestrictsNewChats represents TL type `canSendMessageToUserResultUserRestrictsNewChats#7304e1d5`.
type CanSendMessageToUserResultUserRestrictsNewChats struct {
}

// CanSendMessageToUserResultUserRestrictsNewChatsTypeID is TL type id of CanSendMessageToUserResultUserRestrictsNewChats.
const CanSendMessageToUserResultUserRestrictsNewChatsTypeID = 0x7304e1d5

// construct implements constructor of CanSendMessageToUserResultClass.
func (c CanSendMessageToUserResultUserRestrictsNewChats) construct() CanSendMessageToUserResultClass {
	return &c
}

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

	_ CanSendMessageToUserResultClass = &CanSendMessageToUserResultUserRestrictsNewChats{}
)

func (c *CanSendMessageToUserResultUserRestrictsNewChats) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CanSendMessageToUserResultUserRestrictsNewChats) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5 as nil")
	}
	b.PutID(CanSendMessageToUserResultUserRestrictsNewChatsTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanSendMessageToUserResultUserRestrictsNewChats) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CanSendMessageToUserResultUserRestrictsNewChats) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5 to nil")
	}
	if err := b.ConsumeID(CanSendMessageToUserResultUserRestrictsNewChatsTypeID); err != nil {
		return fmt.Errorf("unable to decode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanSendMessageToUserResultUserRestrictsNewChats) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanSendMessageToUserResultUserRestrictsNewChats) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5 as nil")
	}
	b.ObjStart()
	b.PutID("canSendMessageToUserResultUserRestrictsNewChats")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanSendMessageToUserResultUserRestrictsNewChats) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canSendMessageToUserResultUserRestrictsNewChats#7304e1d5 to nil")
	}

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

// CanSendMessageToUserResultClassName is schema name of CanSendMessageToUserResultClass.
const CanSendMessageToUserResultClassName = "CanSendMessageToUserResult"

// CanSendMessageToUserResultClass represents CanSendMessageToUserResult generic type.
//
// Example:
//
//	g, err := tdapi.DecodeCanSendMessageToUserResult(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.CanSendMessageToUserResultOk: // canSendMessageToUserResultOk#5b3ad802
//	case *tdapi.CanSendMessageToUserResultUserHasPaidMessages: // canSendMessageToUserResultUserHasPaidMessages#afbe3ace
//	case *tdapi.CanSendMessageToUserResultUserIsDeleted: // canSendMessageToUserResultUserIsDeleted#8c172661
//	case *tdapi.CanSendMessageToUserResultUserRestrictsNewChats: // canSendMessageToUserResultUserRestrictsNewChats#7304e1d5
//	default: panic(v)
//	}
type CanSendMessageToUserResultClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() CanSendMessageToUserResultClass

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

// DecodeCanSendMessageToUserResult implements binary de-serialization for CanSendMessageToUserResultClass.
func DecodeCanSendMessageToUserResult(buf *bin.Buffer) (CanSendMessageToUserResultClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case CanSendMessageToUserResultOkTypeID:
		// Decoding canSendMessageToUserResultOk#5b3ad802.
		v := CanSendMessageToUserResultOk{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	case CanSendMessageToUserResultUserHasPaidMessagesTypeID:
		// Decoding canSendMessageToUserResultUserHasPaidMessages#afbe3ace.
		v := CanSendMessageToUserResultUserHasPaidMessages{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	case CanSendMessageToUserResultUserIsDeletedTypeID:
		// Decoding canSendMessageToUserResultUserIsDeleted#8c172661.
		v := CanSendMessageToUserResultUserIsDeleted{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	case CanSendMessageToUserResultUserRestrictsNewChatsTypeID:
		// Decoding canSendMessageToUserResultUserRestrictsNewChats#7304e1d5.
		v := CanSendMessageToUserResultUserRestrictsNewChats{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONCanSendMessageToUserResult implements binary de-serialization for CanSendMessageToUserResultClass.
func DecodeTDLibJSONCanSendMessageToUserResult(buf tdjson.Decoder) (CanSendMessageToUserResultClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "canSendMessageToUserResultOk":
		// Decoding canSendMessageToUserResultOk#5b3ad802.
		v := CanSendMessageToUserResultOk{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	case "canSendMessageToUserResultUserHasPaidMessages":
		// Decoding canSendMessageToUserResultUserHasPaidMessages#afbe3ace.
		v := CanSendMessageToUserResultUserHasPaidMessages{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	case "canSendMessageToUserResultUserIsDeleted":
		// Decoding canSendMessageToUserResultUserIsDeleted#8c172661.
		v := CanSendMessageToUserResultUserIsDeleted{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	case "canSendMessageToUserResultUserRestrictsNewChats":
		// Decoding canSendMessageToUserResultUserRestrictsNewChats#7304e1d5.
		v := CanSendMessageToUserResultUserRestrictsNewChats{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CanSendMessageToUserResultClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// CanSendMessageToUserResult boxes the CanSendMessageToUserResultClass providing a helper.
type CanSendMessageToUserResultBox struct {
	CanSendMessageToUserResult CanSendMessageToUserResultClass
}

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

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

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

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