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

// MaskPointForehead represents TL type `maskPointForehead#3d3e96c5`.
type MaskPointForehead struct {
}

// MaskPointForeheadTypeID is TL type id of MaskPointForehead.
const MaskPointForeheadTypeID = 0x3d3e96c5

// construct implements constructor of MaskPointClass.
func (m MaskPointForehead) construct() MaskPointClass { return &m }

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

	_ MaskPointClass = &MaskPointForehead{}
)

func (m *MaskPointForehead) Zero() bool {
	if m == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (m *MaskPointForehead) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointForehead#3d3e96c5 as nil")
	}
	b.PutID(MaskPointForeheadTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MaskPointForehead) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointForehead#3d3e96c5 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MaskPointForehead) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointForehead#3d3e96c5 to nil")
	}
	if err := b.ConsumeID(MaskPointForeheadTypeID); err != nil {
		return fmt.Errorf("unable to decode maskPointForehead#3d3e96c5: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MaskPointForehead) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointForehead#3d3e96c5 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (m *MaskPointForehead) EncodeTDLibJSON(b tdjson.Encoder) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointForehead#3d3e96c5 as nil")
	}
	b.ObjStart()
	b.PutID("maskPointForehead")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (m *MaskPointForehead) DecodeTDLibJSON(b tdjson.Decoder) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointForehead#3d3e96c5 to nil")
	}

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

// MaskPointEyes represents TL type `maskPointEyes#68351b4d`.
type MaskPointEyes struct {
}

// MaskPointEyesTypeID is TL type id of MaskPointEyes.
const MaskPointEyesTypeID = 0x68351b4d

// construct implements constructor of MaskPointClass.
func (m MaskPointEyes) construct() MaskPointClass { return &m }

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

	_ MaskPointClass = &MaskPointEyes{}
)

func (m *MaskPointEyes) Zero() bool {
	if m == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (m *MaskPointEyes) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointEyes#68351b4d as nil")
	}
	b.PutID(MaskPointEyesTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MaskPointEyes) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointEyes#68351b4d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MaskPointEyes) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointEyes#68351b4d to nil")
	}
	if err := b.ConsumeID(MaskPointEyesTypeID); err != nil {
		return fmt.Errorf("unable to decode maskPointEyes#68351b4d: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MaskPointEyes) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointEyes#68351b4d to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (m *MaskPointEyes) EncodeTDLibJSON(b tdjson.Encoder) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointEyes#68351b4d as nil")
	}
	b.ObjStart()
	b.PutID("maskPointEyes")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (m *MaskPointEyes) DecodeTDLibJSON(b tdjson.Decoder) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointEyes#68351b4d to nil")
	}

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

// MaskPointMouth represents TL type `maskPointMouth#188b29de`.
type MaskPointMouth struct {
}

// MaskPointMouthTypeID is TL type id of MaskPointMouth.
const MaskPointMouthTypeID = 0x188b29de

// construct implements constructor of MaskPointClass.
func (m MaskPointMouth) construct() MaskPointClass { return &m }

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

	_ MaskPointClass = &MaskPointMouth{}
)

func (m *MaskPointMouth) Zero() bool {
	if m == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (m *MaskPointMouth) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointMouth#188b29de as nil")
	}
	b.PutID(MaskPointMouthTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MaskPointMouth) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointMouth#188b29de as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MaskPointMouth) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointMouth#188b29de to nil")
	}
	if err := b.ConsumeID(MaskPointMouthTypeID); err != nil {
		return fmt.Errorf("unable to decode maskPointMouth#188b29de: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MaskPointMouth) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointMouth#188b29de to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (m *MaskPointMouth) EncodeTDLibJSON(b tdjson.Encoder) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointMouth#188b29de as nil")
	}
	b.ObjStart()
	b.PutID("maskPointMouth")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (m *MaskPointMouth) DecodeTDLibJSON(b tdjson.Decoder) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointMouth#188b29de to nil")
	}

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

// MaskPointChin represents TL type `maskPointChin#1fe36187`.
type MaskPointChin struct {
}

// MaskPointChinTypeID is TL type id of MaskPointChin.
const MaskPointChinTypeID = 0x1fe36187

// construct implements constructor of MaskPointClass.
func (m MaskPointChin) construct() MaskPointClass { return &m }

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

	_ MaskPointClass = &MaskPointChin{}
)

func (m *MaskPointChin) Zero() bool {
	if m == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (m *MaskPointChin) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointChin#1fe36187 as nil")
	}
	b.PutID(MaskPointChinTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MaskPointChin) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointChin#1fe36187 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MaskPointChin) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointChin#1fe36187 to nil")
	}
	if err := b.ConsumeID(MaskPointChinTypeID); err != nil {
		return fmt.Errorf("unable to decode maskPointChin#1fe36187: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MaskPointChin) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointChin#1fe36187 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (m *MaskPointChin) EncodeTDLibJSON(b tdjson.Encoder) error {
	if m == nil {
		return fmt.Errorf("can't encode maskPointChin#1fe36187 as nil")
	}
	b.ObjStart()
	b.PutID("maskPointChin")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (m *MaskPointChin) DecodeTDLibJSON(b tdjson.Decoder) error {
	if m == nil {
		return fmt.Errorf("can't decode maskPointChin#1fe36187 to nil")
	}

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

// MaskPointClassName is schema name of MaskPointClass.
const MaskPointClassName = "MaskPoint"

// MaskPointClass represents MaskPoint generic type.
//
// Example:
//
//	g, err := tdapi.DecodeMaskPoint(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.MaskPointForehead: // maskPointForehead#3d3e96c5
//	case *tdapi.MaskPointEyes: // maskPointEyes#68351b4d
//	case *tdapi.MaskPointMouth: // maskPointMouth#188b29de
//	case *tdapi.MaskPointChin: // maskPointChin#1fe36187
//	default: panic(v)
//	}
type MaskPointClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MaskPointClass

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

// DecodeMaskPoint implements binary de-serialization for MaskPointClass.
func DecodeMaskPoint(buf *bin.Buffer) (MaskPointClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case MaskPointForeheadTypeID:
		// Decoding maskPointForehead#3d3e96c5.
		v := MaskPointForehead{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	case MaskPointEyesTypeID:
		// Decoding maskPointEyes#68351b4d.
		v := MaskPointEyes{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	case MaskPointMouthTypeID:
		// Decoding maskPointMouth#188b29de.
		v := MaskPointMouth{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	case MaskPointChinTypeID:
		// Decoding maskPointChin#1fe36187.
		v := MaskPointChin{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MaskPointClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONMaskPoint implements binary de-serialization for MaskPointClass.
func DecodeTDLibJSONMaskPoint(buf tdjson.Decoder) (MaskPointClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "maskPointForehead":
		// Decoding maskPointForehead#3d3e96c5.
		v := MaskPointForehead{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	case "maskPointEyes":
		// Decoding maskPointEyes#68351b4d.
		v := MaskPointEyes{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	case "maskPointMouth":
		// Decoding maskPointMouth#188b29de.
		v := MaskPointMouth{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	case "maskPointChin":
		// Decoding maskPointChin#1fe36187.
		v := MaskPointChin{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MaskPointClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MaskPointClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// MaskPoint boxes the MaskPointClass providing a helper.
type MaskPointBox struct {
	MaskPoint MaskPointClass
}

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

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

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

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