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

// CanTransferOwnershipResultOk represents TL type `canTransferOwnershipResultOk#faa48643`.
type CanTransferOwnershipResultOk struct {
}

// CanTransferOwnershipResultOkTypeID is TL type id of CanTransferOwnershipResultOk.
const CanTransferOwnershipResultOkTypeID = 0xfaa48643

// construct implements constructor of CanTransferOwnershipResultClass.
func (c CanTransferOwnershipResultOk) construct() CanTransferOwnershipResultClass { return &c }

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

	_ CanTransferOwnershipResultClass = &CanTransferOwnershipResultOk{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *CanTransferOwnershipResultOk) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultOk#faa48643 as nil")
	}
	b.PutID(CanTransferOwnershipResultOkTypeID)
	return c.EncodeBare(b)
}

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

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

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

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

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

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

// CanTransferOwnershipResultPasswordNeeded represents TL type `canTransferOwnershipResultPasswordNeeded#5c4a4adf`.
type CanTransferOwnershipResultPasswordNeeded struct {
}

// CanTransferOwnershipResultPasswordNeededTypeID is TL type id of CanTransferOwnershipResultPasswordNeeded.
const CanTransferOwnershipResultPasswordNeededTypeID = 0x5c4a4adf

// construct implements constructor of CanTransferOwnershipResultClass.
func (c CanTransferOwnershipResultPasswordNeeded) construct() CanTransferOwnershipResultClass {
	return &c
}

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

	_ CanTransferOwnershipResultClass = &CanTransferOwnershipResultPasswordNeeded{}
)

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

	return true
}

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

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

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

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

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

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

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

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

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

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

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

// CanTransferOwnershipResultPasswordTooFresh represents TL type `canTransferOwnershipResultPasswordTooFresh#305d9b11`.
type CanTransferOwnershipResultPasswordTooFresh struct {
	// Time left before the session can be used to transfer ownership of a chat, in seconds
	RetryAfter int32
}

// CanTransferOwnershipResultPasswordTooFreshTypeID is TL type id of CanTransferOwnershipResultPasswordTooFresh.
const CanTransferOwnershipResultPasswordTooFreshTypeID = 0x305d9b11

// construct implements constructor of CanTransferOwnershipResultClass.
func (c CanTransferOwnershipResultPasswordTooFresh) construct() CanTransferOwnershipResultClass {
	return &c
}

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

	_ CanTransferOwnershipResultClass = &CanTransferOwnershipResultPasswordTooFresh{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanTransferOwnershipResultPasswordTooFresh) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canTransferOwnershipResultPasswordTooFresh",
		ID:   CanTransferOwnershipResultPasswordTooFreshTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RetryAfter",
			SchemaName: "retry_after",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanTransferOwnershipResultPasswordTooFresh) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultPasswordTooFresh#305d9b11 as nil")
	}
	b.PutID(CanTransferOwnershipResultPasswordTooFreshTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanTransferOwnershipResultPasswordTooFresh) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultPasswordTooFresh#305d9b11 as nil")
	}
	b.PutInt32(c.RetryAfter)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *CanTransferOwnershipResultPasswordTooFresh) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canTransferOwnershipResultPasswordTooFresh#305d9b11 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode canTransferOwnershipResultPasswordTooFresh#305d9b11: field retry_after: %w", err)
		}
		c.RetryAfter = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanTransferOwnershipResultPasswordTooFresh) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultPasswordTooFresh#305d9b11 as nil")
	}
	b.ObjStart()
	b.PutID("canTransferOwnershipResultPasswordTooFresh")
	b.Comma()
	b.FieldStart("retry_after")
	b.PutInt32(c.RetryAfter)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("canTransferOwnershipResultPasswordTooFresh"); err != nil {
				return fmt.Errorf("unable to decode canTransferOwnershipResultPasswordTooFresh#305d9b11: %w", err)
			}
		case "retry_after":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode canTransferOwnershipResultPasswordTooFresh#305d9b11: field retry_after: %w", err)
			}
			c.RetryAfter = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetRetryAfter returns value of RetryAfter field.
func (c *CanTransferOwnershipResultPasswordTooFresh) GetRetryAfter() (value int32) {
	if c == nil {
		return
	}
	return c.RetryAfter
}

// CanTransferOwnershipResultSessionTooFresh represents TL type `canTransferOwnershipResultSessionTooFresh#3ab0c8e1`.
type CanTransferOwnershipResultSessionTooFresh struct {
	// Time left before the session can be used to transfer ownership of a chat, in seconds
	RetryAfter int32
}

// CanTransferOwnershipResultSessionTooFreshTypeID is TL type id of CanTransferOwnershipResultSessionTooFresh.
const CanTransferOwnershipResultSessionTooFreshTypeID = 0x3ab0c8e1

// construct implements constructor of CanTransferOwnershipResultClass.
func (c CanTransferOwnershipResultSessionTooFresh) construct() CanTransferOwnershipResultClass {
	return &c
}

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

	_ CanTransferOwnershipResultClass = &CanTransferOwnershipResultSessionTooFresh{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanTransferOwnershipResultSessionTooFresh) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canTransferOwnershipResultSessionTooFresh",
		ID:   CanTransferOwnershipResultSessionTooFreshTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RetryAfter",
			SchemaName: "retry_after",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanTransferOwnershipResultSessionTooFresh) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultSessionTooFresh#3ab0c8e1 as nil")
	}
	b.PutID(CanTransferOwnershipResultSessionTooFreshTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanTransferOwnershipResultSessionTooFresh) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultSessionTooFresh#3ab0c8e1 as nil")
	}
	b.PutInt32(c.RetryAfter)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *CanTransferOwnershipResultSessionTooFresh) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canTransferOwnershipResultSessionTooFresh#3ab0c8e1 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode canTransferOwnershipResultSessionTooFresh#3ab0c8e1: field retry_after: %w", err)
		}
		c.RetryAfter = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanTransferOwnershipResultSessionTooFresh) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canTransferOwnershipResultSessionTooFresh#3ab0c8e1 as nil")
	}
	b.ObjStart()
	b.PutID("canTransferOwnershipResultSessionTooFresh")
	b.Comma()
	b.FieldStart("retry_after")
	b.PutInt32(c.RetryAfter)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("canTransferOwnershipResultSessionTooFresh"); err != nil {
				return fmt.Errorf("unable to decode canTransferOwnershipResultSessionTooFresh#3ab0c8e1: %w", err)
			}
		case "retry_after":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode canTransferOwnershipResultSessionTooFresh#3ab0c8e1: field retry_after: %w", err)
			}
			c.RetryAfter = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetRetryAfter returns value of RetryAfter field.
func (c *CanTransferOwnershipResultSessionTooFresh) GetRetryAfter() (value int32) {
	if c == nil {
		return
	}
	return c.RetryAfter
}

// CanTransferOwnershipResultClassName is schema name of CanTransferOwnershipResultClass.
const CanTransferOwnershipResultClassName = "CanTransferOwnershipResult"

// CanTransferOwnershipResultClass represents CanTransferOwnershipResult generic type.
//
// Example:
//
//	g, err := tdapi.DecodeCanTransferOwnershipResult(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.CanTransferOwnershipResultOk: // canTransferOwnershipResultOk#faa48643
//	case *tdapi.CanTransferOwnershipResultPasswordNeeded: // canTransferOwnershipResultPasswordNeeded#5c4a4adf
//	case *tdapi.CanTransferOwnershipResultPasswordTooFresh: // canTransferOwnershipResultPasswordTooFresh#305d9b11
//	case *tdapi.CanTransferOwnershipResultSessionTooFresh: // canTransferOwnershipResultSessionTooFresh#3ab0c8e1
//	default: panic(v)
//	}
type CanTransferOwnershipResultClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() CanTransferOwnershipResultClass

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

// DecodeCanTransferOwnershipResult implements binary de-serialization for CanTransferOwnershipResultClass.
func DecodeCanTransferOwnershipResult(buf *bin.Buffer) (CanTransferOwnershipResultClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case CanTransferOwnershipResultOkTypeID:
		// Decoding canTransferOwnershipResultOk#faa48643.
		v := CanTransferOwnershipResultOk{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	case CanTransferOwnershipResultPasswordNeededTypeID:
		// Decoding canTransferOwnershipResultPasswordNeeded#5c4a4adf.
		v := CanTransferOwnershipResultPasswordNeeded{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	case CanTransferOwnershipResultPasswordTooFreshTypeID:
		// Decoding canTransferOwnershipResultPasswordTooFresh#305d9b11.
		v := CanTransferOwnershipResultPasswordTooFresh{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	case CanTransferOwnershipResultSessionTooFreshTypeID:
		// Decoding canTransferOwnershipResultSessionTooFresh#3ab0c8e1.
		v := CanTransferOwnershipResultSessionTooFresh{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONCanTransferOwnershipResult implements binary de-serialization for CanTransferOwnershipResultClass.
func DecodeTDLibJSONCanTransferOwnershipResult(buf tdjson.Decoder) (CanTransferOwnershipResultClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "canTransferOwnershipResultOk":
		// Decoding canTransferOwnershipResultOk#faa48643.
		v := CanTransferOwnershipResultOk{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	case "canTransferOwnershipResultPasswordNeeded":
		// Decoding canTransferOwnershipResultPasswordNeeded#5c4a4adf.
		v := CanTransferOwnershipResultPasswordNeeded{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	case "canTransferOwnershipResultPasswordTooFresh":
		// Decoding canTransferOwnershipResultPasswordTooFresh#305d9b11.
		v := CanTransferOwnershipResultPasswordTooFresh{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	case "canTransferOwnershipResultSessionTooFresh":
		// Decoding canTransferOwnershipResultSessionTooFresh#3ab0c8e1.
		v := CanTransferOwnershipResultSessionTooFresh{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CanTransferOwnershipResultClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// CanTransferOwnershipResult boxes the CanTransferOwnershipResultClass providing a helper.
type CanTransferOwnershipResultBox struct {
	CanTransferOwnershipResult CanTransferOwnershipResultClass
}

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

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

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

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