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

// WebAppOpenModeCompact represents TL type `webAppOpenModeCompact#6604ffdb`.
type WebAppOpenModeCompact struct {
}

// WebAppOpenModeCompactTypeID is TL type id of WebAppOpenModeCompact.
const WebAppOpenModeCompactTypeID = 0x6604ffdb

// construct implements constructor of WebAppOpenModeClass.
func (w WebAppOpenModeCompact) construct() WebAppOpenModeClass { return &w }

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

	_ WebAppOpenModeClass = &WebAppOpenModeCompact{}
)

func (w *WebAppOpenModeCompact) Zero() bool {
	if w == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (w *WebAppOpenModeCompact) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeCompact#6604ffdb as nil")
	}
	b.PutID(WebAppOpenModeCompactTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebAppOpenModeCompact) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeCompact#6604ffdb as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (w *WebAppOpenModeCompact) Decode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeCompact#6604ffdb to nil")
	}
	if err := b.ConsumeID(WebAppOpenModeCompactTypeID); err != nil {
		return fmt.Errorf("unable to decode webAppOpenModeCompact#6604ffdb: %w", err)
	}
	return w.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (w *WebAppOpenModeCompact) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeCompact#6604ffdb to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (w *WebAppOpenModeCompact) EncodeTDLibJSON(b tdjson.Encoder) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeCompact#6604ffdb as nil")
	}
	b.ObjStart()
	b.PutID("webAppOpenModeCompact")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (w *WebAppOpenModeCompact) DecodeTDLibJSON(b tdjson.Decoder) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeCompact#6604ffdb to nil")
	}

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

// WebAppOpenModeFullSize represents TL type `webAppOpenModeFullSize#b48cd41`.
type WebAppOpenModeFullSize struct {
}

// WebAppOpenModeFullSizeTypeID is TL type id of WebAppOpenModeFullSize.
const WebAppOpenModeFullSizeTypeID = 0xb48cd41

// construct implements constructor of WebAppOpenModeClass.
func (w WebAppOpenModeFullSize) construct() WebAppOpenModeClass { return &w }

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

	_ WebAppOpenModeClass = &WebAppOpenModeFullSize{}
)

func (w *WebAppOpenModeFullSize) Zero() bool {
	if w == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (w *WebAppOpenModeFullSize) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeFullSize#b48cd41 as nil")
	}
	b.PutID(WebAppOpenModeFullSizeTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebAppOpenModeFullSize) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeFullSize#b48cd41 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (w *WebAppOpenModeFullSize) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeFullSize#b48cd41 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (w *WebAppOpenModeFullSize) DecodeTDLibJSON(b tdjson.Decoder) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeFullSize#b48cd41 to nil")
	}

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

// WebAppOpenModeFullScreen represents TL type `webAppOpenModeFullScreen#6f8a019d`.
type WebAppOpenModeFullScreen struct {
}

// WebAppOpenModeFullScreenTypeID is TL type id of WebAppOpenModeFullScreen.
const WebAppOpenModeFullScreenTypeID = 0x6f8a019d

// construct implements constructor of WebAppOpenModeClass.
func (w WebAppOpenModeFullScreen) construct() WebAppOpenModeClass { return &w }

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

	_ WebAppOpenModeClass = &WebAppOpenModeFullScreen{}
)

func (w *WebAppOpenModeFullScreen) Zero() bool {
	if w == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (w *WebAppOpenModeFullScreen) Encode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeFullScreen#6f8a019d as nil")
	}
	b.PutID(WebAppOpenModeFullScreenTypeID)
	return w.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (w *WebAppOpenModeFullScreen) EncodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeFullScreen#6f8a019d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (w *WebAppOpenModeFullScreen) Decode(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeFullScreen#6f8a019d to nil")
	}
	if err := b.ConsumeID(WebAppOpenModeFullScreenTypeID); err != nil {
		return fmt.Errorf("unable to decode webAppOpenModeFullScreen#6f8a019d: %w", err)
	}
	return w.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (w *WebAppOpenModeFullScreen) DecodeBare(b *bin.Buffer) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeFullScreen#6f8a019d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (w *WebAppOpenModeFullScreen) EncodeTDLibJSON(b tdjson.Encoder) error {
	if w == nil {
		return fmt.Errorf("can't encode webAppOpenModeFullScreen#6f8a019d as nil")
	}
	b.ObjStart()
	b.PutID("webAppOpenModeFullScreen")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (w *WebAppOpenModeFullScreen) DecodeTDLibJSON(b tdjson.Decoder) error {
	if w == nil {
		return fmt.Errorf("can't decode webAppOpenModeFullScreen#6f8a019d to nil")
	}

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

// WebAppOpenModeClassName is schema name of WebAppOpenModeClass.
const WebAppOpenModeClassName = "WebAppOpenMode"

// WebAppOpenModeClass represents WebAppOpenMode generic type.
//
// Example:
//
//	g, err := tdapi.DecodeWebAppOpenMode(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.WebAppOpenModeCompact: // webAppOpenModeCompact#6604ffdb
//	case *tdapi.WebAppOpenModeFullSize: // webAppOpenModeFullSize#b48cd41
//	case *tdapi.WebAppOpenModeFullScreen: // webAppOpenModeFullScreen#6f8a019d
//	default: panic(v)
//	}
type WebAppOpenModeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() WebAppOpenModeClass

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

// DecodeWebAppOpenMode implements binary de-serialization for WebAppOpenModeClass.
func DecodeWebAppOpenMode(buf *bin.Buffer) (WebAppOpenModeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case WebAppOpenModeCompactTypeID:
		// Decoding webAppOpenModeCompact#6604ffdb.
		v := WebAppOpenModeCompact{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", err)
		}
		return &v, nil
	case WebAppOpenModeFullSizeTypeID:
		// Decoding webAppOpenModeFullSize#b48cd41.
		v := WebAppOpenModeFullSize{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", err)
		}
		return &v, nil
	case WebAppOpenModeFullScreenTypeID:
		// Decoding webAppOpenModeFullScreen#6f8a019d.
		v := WebAppOpenModeFullScreen{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONWebAppOpenMode implements binary de-serialization for WebAppOpenModeClass.
func DecodeTDLibJSONWebAppOpenMode(buf tdjson.Decoder) (WebAppOpenModeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "webAppOpenModeCompact":
		// Decoding webAppOpenModeCompact#6604ffdb.
		v := WebAppOpenModeCompact{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", err)
		}
		return &v, nil
	case "webAppOpenModeFullSize":
		// Decoding webAppOpenModeFullSize#b48cd41.
		v := WebAppOpenModeFullSize{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", err)
		}
		return &v, nil
	case "webAppOpenModeFullScreen":
		// Decoding webAppOpenModeFullScreen#6f8a019d.
		v := WebAppOpenModeFullScreen{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode WebAppOpenModeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// WebAppOpenMode boxes the WebAppOpenModeClass providing a helper.
type WebAppOpenModeBox struct {
	WebAppOpenMode WebAppOpenModeClass
}

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

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

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

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