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

// PageBlockHorizontalAlignmentLeft represents TL type `pageBlockHorizontalAlignmentLeft#329627e9`.
type PageBlockHorizontalAlignmentLeft struct {
}

// PageBlockHorizontalAlignmentLeftTypeID is TL type id of PageBlockHorizontalAlignmentLeft.
const PageBlockHorizontalAlignmentLeftTypeID = 0x329627e9

// construct implements constructor of PageBlockHorizontalAlignmentClass.
func (p PageBlockHorizontalAlignmentLeft) construct() PageBlockHorizontalAlignmentClass { return &p }

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

	_ PageBlockHorizontalAlignmentClass = &PageBlockHorizontalAlignmentLeft{}
)

func (p *PageBlockHorizontalAlignmentLeft) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PageBlockHorizontalAlignmentLeft) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentLeft#329627e9 as nil")
	}
	b.PutID(PageBlockHorizontalAlignmentLeftTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PageBlockHorizontalAlignmentLeft) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentLeft#329627e9 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PageBlockHorizontalAlignmentLeft) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentLeft#329627e9 to nil")
	}
	if err := b.ConsumeID(PageBlockHorizontalAlignmentLeftTypeID); err != nil {
		return fmt.Errorf("unable to decode pageBlockHorizontalAlignmentLeft#329627e9: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PageBlockHorizontalAlignmentLeft) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentLeft#329627e9 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PageBlockHorizontalAlignmentLeft) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentLeft#329627e9 as nil")
	}
	b.ObjStart()
	b.PutID("pageBlockHorizontalAlignmentLeft")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PageBlockHorizontalAlignmentLeft) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentLeft#329627e9 to nil")
	}

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

// PageBlockHorizontalAlignmentCenter represents TL type `pageBlockHorizontalAlignmentCenter#c3d8c4ea`.
type PageBlockHorizontalAlignmentCenter struct {
}

// PageBlockHorizontalAlignmentCenterTypeID is TL type id of PageBlockHorizontalAlignmentCenter.
const PageBlockHorizontalAlignmentCenterTypeID = 0xc3d8c4ea

// construct implements constructor of PageBlockHorizontalAlignmentClass.
func (p PageBlockHorizontalAlignmentCenter) construct() PageBlockHorizontalAlignmentClass { return &p }

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

	_ PageBlockHorizontalAlignmentClass = &PageBlockHorizontalAlignmentCenter{}
)

func (p *PageBlockHorizontalAlignmentCenter) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PageBlockHorizontalAlignmentCenter) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentCenter#c3d8c4ea as nil")
	}
	b.PutID(PageBlockHorizontalAlignmentCenterTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PageBlockHorizontalAlignmentCenter) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentCenter#c3d8c4ea as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (p *PageBlockHorizontalAlignmentCenter) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentCenter#c3d8c4ea to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PageBlockHorizontalAlignmentCenter) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentCenter#c3d8c4ea to nil")
	}

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

// PageBlockHorizontalAlignmentRight represents TL type `pageBlockHorizontalAlignmentRight#51bd6efe`.
type PageBlockHorizontalAlignmentRight struct {
}

// PageBlockHorizontalAlignmentRightTypeID is TL type id of PageBlockHorizontalAlignmentRight.
const PageBlockHorizontalAlignmentRightTypeID = 0x51bd6efe

// construct implements constructor of PageBlockHorizontalAlignmentClass.
func (p PageBlockHorizontalAlignmentRight) construct() PageBlockHorizontalAlignmentClass { return &p }

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

	_ PageBlockHorizontalAlignmentClass = &PageBlockHorizontalAlignmentRight{}
)

func (p *PageBlockHorizontalAlignmentRight) Zero() bool {
	if p == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (p *PageBlockHorizontalAlignmentRight) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentRight#51bd6efe as nil")
	}
	b.PutID(PageBlockHorizontalAlignmentRightTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *PageBlockHorizontalAlignmentRight) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentRight#51bd6efe as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (p *PageBlockHorizontalAlignmentRight) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentRight#51bd6efe to nil")
	}
	if err := b.ConsumeID(PageBlockHorizontalAlignmentRightTypeID); err != nil {
		return fmt.Errorf("unable to decode pageBlockHorizontalAlignmentRight#51bd6efe: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *PageBlockHorizontalAlignmentRight) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentRight#51bd6efe to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (p *PageBlockHorizontalAlignmentRight) EncodeTDLibJSON(b tdjson.Encoder) error {
	if p == nil {
		return fmt.Errorf("can't encode pageBlockHorizontalAlignmentRight#51bd6efe as nil")
	}
	b.ObjStart()
	b.PutID("pageBlockHorizontalAlignmentRight")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (p *PageBlockHorizontalAlignmentRight) DecodeTDLibJSON(b tdjson.Decoder) error {
	if p == nil {
		return fmt.Errorf("can't decode pageBlockHorizontalAlignmentRight#51bd6efe to nil")
	}

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

// PageBlockHorizontalAlignmentClassName is schema name of PageBlockHorizontalAlignmentClass.
const PageBlockHorizontalAlignmentClassName = "PageBlockHorizontalAlignment"

// PageBlockHorizontalAlignmentClass represents PageBlockHorizontalAlignment generic type.
//
// Example:
//
//	g, err := tdapi.DecodePageBlockHorizontalAlignment(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.PageBlockHorizontalAlignmentLeft: // pageBlockHorizontalAlignmentLeft#329627e9
//	case *tdapi.PageBlockHorizontalAlignmentCenter: // pageBlockHorizontalAlignmentCenter#c3d8c4ea
//	case *tdapi.PageBlockHorizontalAlignmentRight: // pageBlockHorizontalAlignmentRight#51bd6efe
//	default: panic(v)
//	}
type PageBlockHorizontalAlignmentClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PageBlockHorizontalAlignmentClass

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

// DecodePageBlockHorizontalAlignment implements binary de-serialization for PageBlockHorizontalAlignmentClass.
func DecodePageBlockHorizontalAlignment(buf *bin.Buffer) (PageBlockHorizontalAlignmentClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case PageBlockHorizontalAlignmentLeftTypeID:
		// Decoding pageBlockHorizontalAlignmentLeft#329627e9.
		v := PageBlockHorizontalAlignmentLeft{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", err)
		}
		return &v, nil
	case PageBlockHorizontalAlignmentCenterTypeID:
		// Decoding pageBlockHorizontalAlignmentCenter#c3d8c4ea.
		v := PageBlockHorizontalAlignmentCenter{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", err)
		}
		return &v, nil
	case PageBlockHorizontalAlignmentRightTypeID:
		// Decoding pageBlockHorizontalAlignmentRight#51bd6efe.
		v := PageBlockHorizontalAlignmentRight{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONPageBlockHorizontalAlignment implements binary de-serialization for PageBlockHorizontalAlignmentClass.
func DecodeTDLibJSONPageBlockHorizontalAlignment(buf tdjson.Decoder) (PageBlockHorizontalAlignmentClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "pageBlockHorizontalAlignmentLeft":
		// Decoding pageBlockHorizontalAlignmentLeft#329627e9.
		v := PageBlockHorizontalAlignmentLeft{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", err)
		}
		return &v, nil
	case "pageBlockHorizontalAlignmentCenter":
		// Decoding pageBlockHorizontalAlignmentCenter#c3d8c4ea.
		v := PageBlockHorizontalAlignmentCenter{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", err)
		}
		return &v, nil
	case "pageBlockHorizontalAlignmentRight":
		// Decoding pageBlockHorizontalAlignmentRight#51bd6efe.
		v := PageBlockHorizontalAlignmentRight{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode PageBlockHorizontalAlignmentClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// PageBlockHorizontalAlignment boxes the PageBlockHorizontalAlignmentClass providing a helper.
type PageBlockHorizontalAlignmentBox struct {
	PageBlockHorizontalAlignment PageBlockHorizontalAlignmentClass
}

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

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

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

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