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

// BotWriteAccessAllowReasonConnectedWebsite represents TL type `botWriteAccessAllowReasonConnectedWebsite#782eafe3`.
type BotWriteAccessAllowReasonConnectedWebsite struct {
	// Domain name of the connected website
	DomainName string
}

// BotWriteAccessAllowReasonConnectedWebsiteTypeID is TL type id of BotWriteAccessAllowReasonConnectedWebsite.
const BotWriteAccessAllowReasonConnectedWebsiteTypeID = 0x782eafe3

// construct implements constructor of BotWriteAccessAllowReasonClass.
func (b BotWriteAccessAllowReasonConnectedWebsite) construct() BotWriteAccessAllowReasonClass {
	return &b
}

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

	_ BotWriteAccessAllowReasonClass = &BotWriteAccessAllowReasonConnectedWebsite{}
)

func (b *BotWriteAccessAllowReasonConnectedWebsite) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.DomainName == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (b *BotWriteAccessAllowReasonConnectedWebsite) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "botWriteAccessAllowReasonConnectedWebsite",
		ID:   BotWriteAccessAllowReasonConnectedWebsiteTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DomainName",
			SchemaName: "domain_name",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (b *BotWriteAccessAllowReasonConnectedWebsite) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonConnectedWebsite#782eafe3 as nil")
	}
	buf.PutID(BotWriteAccessAllowReasonConnectedWebsiteTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BotWriteAccessAllowReasonConnectedWebsite) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonConnectedWebsite#782eafe3 as nil")
	}
	buf.PutString(b.DomainName)
	return nil
}

// Decode implements bin.Decoder.
func (b *BotWriteAccessAllowReasonConnectedWebsite) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonConnectedWebsite#782eafe3 to nil")
	}
	if err := buf.ConsumeID(BotWriteAccessAllowReasonConnectedWebsiteTypeID); err != nil {
		return fmt.Errorf("unable to decode botWriteAccessAllowReasonConnectedWebsite#782eafe3: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BotWriteAccessAllowReasonConnectedWebsite) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonConnectedWebsite#782eafe3 to nil")
	}
	{
		value, err := buf.String()
		if err != nil {
			return fmt.Errorf("unable to decode botWriteAccessAllowReasonConnectedWebsite#782eafe3: field domain_name: %w", err)
		}
		b.DomainName = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (b *BotWriteAccessAllowReasonConnectedWebsite) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonConnectedWebsite#782eafe3 as nil")
	}
	buf.ObjStart()
	buf.PutID("botWriteAccessAllowReasonConnectedWebsite")
	buf.Comma()
	buf.FieldStart("domain_name")
	buf.PutString(b.DomainName)
	buf.Comma()
	buf.StripComma()
	buf.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (b *BotWriteAccessAllowReasonConnectedWebsite) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonConnectedWebsite#782eafe3 to nil")
	}

	return buf.Obj(func(buf tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := buf.ConsumeID("botWriteAccessAllowReasonConnectedWebsite"); err != nil {
				return fmt.Errorf("unable to decode botWriteAccessAllowReasonConnectedWebsite#782eafe3: %w", err)
			}
		case "domain_name":
			value, err := buf.String()
			if err != nil {
				return fmt.Errorf("unable to decode botWriteAccessAllowReasonConnectedWebsite#782eafe3: field domain_name: %w", err)
			}
			b.DomainName = value
		default:
			return buf.Skip()
		}
		return nil
	})
}

// GetDomainName returns value of DomainName field.
func (b *BotWriteAccessAllowReasonConnectedWebsite) GetDomainName() (value string) {
	if b == nil {
		return
	}
	return b.DomainName
}

// BotWriteAccessAllowReasonAddedToAttachmentMenu represents TL type `botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d`.
type BotWriteAccessAllowReasonAddedToAttachmentMenu struct {
}

// BotWriteAccessAllowReasonAddedToAttachmentMenuTypeID is TL type id of BotWriteAccessAllowReasonAddedToAttachmentMenu.
const BotWriteAccessAllowReasonAddedToAttachmentMenuTypeID = 0x828b5f9d

// construct implements constructor of BotWriteAccessAllowReasonClass.
func (b BotWriteAccessAllowReasonAddedToAttachmentMenu) construct() BotWriteAccessAllowReasonClass {
	return &b
}

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

	_ BotWriteAccessAllowReasonClass = &BotWriteAccessAllowReasonAddedToAttachmentMenu{}
)

func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) Zero() bool {
	if b == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d as nil")
	}
	buf.PutID(BotWriteAccessAllowReasonAddedToAttachmentMenuTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d to nil")
	}
	if err := buf.ConsumeID(BotWriteAccessAllowReasonAddedToAttachmentMenuTypeID); err != nil {
		return fmt.Errorf("unable to decode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d as nil")
	}
	buf.ObjStart()
	buf.PutID("botWriteAccessAllowReasonAddedToAttachmentMenu")
	buf.Comma()
	buf.StripComma()
	buf.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (b *BotWriteAccessAllowReasonAddedToAttachmentMenu) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d to nil")
	}

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

// BotWriteAccessAllowReasonLaunchedWebApp represents TL type `botWriteAccessAllowReasonLaunchedWebApp#f1a504d7`.
type BotWriteAccessAllowReasonLaunchedWebApp struct {
	// Information about the Web App
	WebApp WebApp
}

// BotWriteAccessAllowReasonLaunchedWebAppTypeID is TL type id of BotWriteAccessAllowReasonLaunchedWebApp.
const BotWriteAccessAllowReasonLaunchedWebAppTypeID = 0xf1a504d7

// construct implements constructor of BotWriteAccessAllowReasonClass.
func (b BotWriteAccessAllowReasonLaunchedWebApp) construct() BotWriteAccessAllowReasonClass {
	return &b
}

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

	_ BotWriteAccessAllowReasonClass = &BotWriteAccessAllowReasonLaunchedWebApp{}
)

func (b *BotWriteAccessAllowReasonLaunchedWebApp) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.WebApp.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "botWriteAccessAllowReasonLaunchedWebApp",
		ID:   BotWriteAccessAllowReasonLaunchedWebAppTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "WebApp",
			SchemaName: "web_app",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7 as nil")
	}
	buf.PutID(BotWriteAccessAllowReasonLaunchedWebAppTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7 as nil")
	}
	if err := b.WebApp.Encode(buf); err != nil {
		return fmt.Errorf("unable to encode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7: field web_app: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7 to nil")
	}
	if err := buf.ConsumeID(BotWriteAccessAllowReasonLaunchedWebAppTypeID); err != nil {
		return fmt.Errorf("unable to decode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7 to nil")
	}
	{
		if err := b.WebApp.Decode(buf); err != nil {
			return fmt.Errorf("unable to decode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7: field web_app: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7 as nil")
	}
	buf.ObjStart()
	buf.PutID("botWriteAccessAllowReasonLaunchedWebApp")
	buf.Comma()
	buf.FieldStart("web_app")
	if err := b.WebApp.EncodeTDLibJSON(buf); err != nil {
		return fmt.Errorf("unable to encode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7: field web_app: %w", err)
	}
	buf.Comma()
	buf.StripComma()
	buf.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonLaunchedWebApp#f1a504d7 to nil")
	}

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

// GetWebApp returns value of WebApp field.
func (b *BotWriteAccessAllowReasonLaunchedWebApp) GetWebApp() (value WebApp) {
	if b == nil {
		return
	}
	return b.WebApp
}

// BotWriteAccessAllowReasonAcceptedRequest represents TL type `botWriteAccessAllowReasonAcceptedRequest#89c63bfc`.
type BotWriteAccessAllowReasonAcceptedRequest struct {
}

// BotWriteAccessAllowReasonAcceptedRequestTypeID is TL type id of BotWriteAccessAllowReasonAcceptedRequest.
const BotWriteAccessAllowReasonAcceptedRequestTypeID = 0x89c63bfc

// construct implements constructor of BotWriteAccessAllowReasonClass.
func (b BotWriteAccessAllowReasonAcceptedRequest) construct() BotWriteAccessAllowReasonClass {
	return &b
}

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

	_ BotWriteAccessAllowReasonClass = &BotWriteAccessAllowReasonAcceptedRequest{}
)

func (b *BotWriteAccessAllowReasonAcceptedRequest) Zero() bool {
	if b == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (b *BotWriteAccessAllowReasonAcceptedRequest) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonAcceptedRequest#89c63bfc as nil")
	}
	buf.PutID(BotWriteAccessAllowReasonAcceptedRequestTypeID)
	return b.EncodeBare(buf)
}

// EncodeBare implements bin.BareEncoder.
func (b *BotWriteAccessAllowReasonAcceptedRequest) EncodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonAcceptedRequest#89c63bfc as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (b *BotWriteAccessAllowReasonAcceptedRequest) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonAcceptedRequest#89c63bfc to nil")
	}
	if err := buf.ConsumeID(BotWriteAccessAllowReasonAcceptedRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode botWriteAccessAllowReasonAcceptedRequest#89c63bfc: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BotWriteAccessAllowReasonAcceptedRequest) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonAcceptedRequest#89c63bfc to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (b *BotWriteAccessAllowReasonAcceptedRequest) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil {
		return fmt.Errorf("can't encode botWriteAccessAllowReasonAcceptedRequest#89c63bfc as nil")
	}
	buf.ObjStart()
	buf.PutID("botWriteAccessAllowReasonAcceptedRequest")
	buf.Comma()
	buf.StripComma()
	buf.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (b *BotWriteAccessAllowReasonAcceptedRequest) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("can't decode botWriteAccessAllowReasonAcceptedRequest#89c63bfc to nil")
	}

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

// BotWriteAccessAllowReasonClassName is schema name of BotWriteAccessAllowReasonClass.
const BotWriteAccessAllowReasonClassName = "BotWriteAccessAllowReason"

// BotWriteAccessAllowReasonClass represents BotWriteAccessAllowReason generic type.
//
// Example:
//
//	g, err := tdapi.DecodeBotWriteAccessAllowReason(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.BotWriteAccessAllowReasonConnectedWebsite: // botWriteAccessAllowReasonConnectedWebsite#782eafe3
//	case *tdapi.BotWriteAccessAllowReasonAddedToAttachmentMenu: // botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d
//	case *tdapi.BotWriteAccessAllowReasonLaunchedWebApp: // botWriteAccessAllowReasonLaunchedWebApp#f1a504d7
//	case *tdapi.BotWriteAccessAllowReasonAcceptedRequest: // botWriteAccessAllowReasonAcceptedRequest#89c63bfc
//	default: panic(v)
//	}
type BotWriteAccessAllowReasonClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() BotWriteAccessAllowReasonClass

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

// DecodeBotWriteAccessAllowReason implements binary de-serialization for BotWriteAccessAllowReasonClass.
func DecodeBotWriteAccessAllowReason(buf *bin.Buffer) (BotWriteAccessAllowReasonClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case BotWriteAccessAllowReasonConnectedWebsiteTypeID:
		// Decoding botWriteAccessAllowReasonConnectedWebsite#782eafe3.
		v := BotWriteAccessAllowReasonConnectedWebsite{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	case BotWriteAccessAllowReasonAddedToAttachmentMenuTypeID:
		// Decoding botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d.
		v := BotWriteAccessAllowReasonAddedToAttachmentMenu{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	case BotWriteAccessAllowReasonLaunchedWebAppTypeID:
		// Decoding botWriteAccessAllowReasonLaunchedWebApp#f1a504d7.
		v := BotWriteAccessAllowReasonLaunchedWebApp{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	case BotWriteAccessAllowReasonAcceptedRequestTypeID:
		// Decoding botWriteAccessAllowReasonAcceptedRequest#89c63bfc.
		v := BotWriteAccessAllowReasonAcceptedRequest{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONBotWriteAccessAllowReason implements binary de-serialization for BotWriteAccessAllowReasonClass.
func DecodeTDLibJSONBotWriteAccessAllowReason(buf tdjson.Decoder) (BotWriteAccessAllowReasonClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "botWriteAccessAllowReasonConnectedWebsite":
		// Decoding botWriteAccessAllowReasonConnectedWebsite#782eafe3.
		v := BotWriteAccessAllowReasonConnectedWebsite{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	case "botWriteAccessAllowReasonAddedToAttachmentMenu":
		// Decoding botWriteAccessAllowReasonAddedToAttachmentMenu#828b5f9d.
		v := BotWriteAccessAllowReasonAddedToAttachmentMenu{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	case "botWriteAccessAllowReasonLaunchedWebApp":
		// Decoding botWriteAccessAllowReasonLaunchedWebApp#f1a504d7.
		v := BotWriteAccessAllowReasonLaunchedWebApp{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	case "botWriteAccessAllowReasonAcceptedRequest":
		// Decoding botWriteAccessAllowReasonAcceptedRequest#89c63bfc.
		v := BotWriteAccessAllowReasonAcceptedRequest{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode BotWriteAccessAllowReasonClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// BotWriteAccessAllowReason boxes the BotWriteAccessAllowReasonClass providing a helper.
type BotWriteAccessAllowReasonBox struct {
	BotWriteAccessAllowReason BotWriteAccessAllowReasonClass
}

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

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

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

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