// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// InputAiComposeToneDefault represents TL type `inputAiComposeToneDefault#1fe9a9bf`.
//
// See https://core.telegram.org/constructor/inputAiComposeToneDefault for reference.
type InputAiComposeToneDefault struct {
	// Tone field of InputAiComposeToneDefault.
	Tone string
}

// InputAiComposeToneDefaultTypeID is TL type id of InputAiComposeToneDefault.
const InputAiComposeToneDefaultTypeID = 0x1fe9a9bf

// construct implements constructor of InputAiComposeToneClass.
func (i InputAiComposeToneDefault) construct() InputAiComposeToneClass { return &i }

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

	_ InputAiComposeToneClass = &InputAiComposeToneDefault{}
)

func (i *InputAiComposeToneDefault) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.Tone == "") {
		return false
	}

	return true
}

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

// FillFrom fills InputAiComposeToneDefault from given interface.
func (i *InputAiComposeToneDefault) FillFrom(from interface {
	GetTone() (value string)
}) {
	i.Tone = from.GetTone()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputAiComposeToneDefault) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputAiComposeToneDefault",
		ID:   InputAiComposeToneDefaultTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Tone",
			SchemaName: "tone",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputAiComposeToneDefault) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputAiComposeToneDefault#1fe9a9bf as nil")
	}
	b.PutID(InputAiComposeToneDefaultTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputAiComposeToneDefault) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputAiComposeToneDefault#1fe9a9bf as nil")
	}
	b.PutString(i.Tone)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputAiComposeToneDefault) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputAiComposeToneDefault#1fe9a9bf to nil")
	}
	if err := b.ConsumeID(InputAiComposeToneDefaultTypeID); err != nil {
		return fmt.Errorf("unable to decode inputAiComposeToneDefault#1fe9a9bf: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputAiComposeToneDefault) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputAiComposeToneDefault#1fe9a9bf to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode inputAiComposeToneDefault#1fe9a9bf: field tone: %w", err)
		}
		i.Tone = value
	}
	return nil
}

// GetTone returns value of Tone field.
func (i *InputAiComposeToneDefault) GetTone() (value string) {
	if i == nil {
		return
	}
	return i.Tone
}

// InputAiComposeToneID represents TL type `inputAiComposeToneID#773c080`.
//
// See https://core.telegram.org/constructor/inputAiComposeToneID for reference.
type InputAiComposeToneID struct {
	// ID field of InputAiComposeToneID.
	ID int64
	// AccessHash field of InputAiComposeToneID.
	AccessHash int64
}

// InputAiComposeToneIDTypeID is TL type id of InputAiComposeToneID.
const InputAiComposeToneIDTypeID = 0x773c080

// construct implements constructor of InputAiComposeToneClass.
func (i InputAiComposeToneID) construct() InputAiComposeToneClass { return &i }

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

	_ InputAiComposeToneClass = &InputAiComposeToneID{}
)

func (i *InputAiComposeToneID) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.ID == 0) {
		return false
	}
	if !(i.AccessHash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills InputAiComposeToneID from given interface.
func (i *InputAiComposeToneID) FillFrom(from interface {
	GetID() (value int64)
	GetAccessHash() (value int64)
}) {
	i.ID = from.GetID()
	i.AccessHash = from.GetAccessHash()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputAiComposeToneID) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputAiComposeToneID",
		ID:   InputAiComposeToneIDTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputAiComposeToneID) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputAiComposeToneID#773c080 as nil")
	}
	b.PutID(InputAiComposeToneIDTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputAiComposeToneID) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputAiComposeToneID#773c080 as nil")
	}
	b.PutLong(i.ID)
	b.PutLong(i.AccessHash)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputAiComposeToneID) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputAiComposeToneID#773c080 to nil")
	}
	if err := b.ConsumeID(InputAiComposeToneIDTypeID); err != nil {
		return fmt.Errorf("unable to decode inputAiComposeToneID#773c080: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputAiComposeToneID) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputAiComposeToneID#773c080 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputAiComposeToneID#773c080: field id: %w", err)
		}
		i.ID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputAiComposeToneID#773c080: field access_hash: %w", err)
		}
		i.AccessHash = value
	}
	return nil
}

// GetID returns value of ID field.
func (i *InputAiComposeToneID) GetID() (value int64) {
	if i == nil {
		return
	}
	return i.ID
}

// GetAccessHash returns value of AccessHash field.
func (i *InputAiComposeToneID) GetAccessHash() (value int64) {
	if i == nil {
		return
	}
	return i.AccessHash
}

// InputAiComposeToneSlug represents TL type `inputAiComposeToneSlug#1fa01357`.
//
// See https://core.telegram.org/constructor/inputAiComposeToneSlug for reference.
type InputAiComposeToneSlug struct {
	// Slug field of InputAiComposeToneSlug.
	Slug string
}

// InputAiComposeToneSlugTypeID is TL type id of InputAiComposeToneSlug.
const InputAiComposeToneSlugTypeID = 0x1fa01357

// construct implements constructor of InputAiComposeToneClass.
func (i InputAiComposeToneSlug) construct() InputAiComposeToneClass { return &i }

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

	_ InputAiComposeToneClass = &InputAiComposeToneSlug{}
)

func (i *InputAiComposeToneSlug) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.Slug == "") {
		return false
	}

	return true
}

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

// FillFrom fills InputAiComposeToneSlug from given interface.
func (i *InputAiComposeToneSlug) FillFrom(from interface {
	GetSlug() (value string)
}) {
	i.Slug = from.GetSlug()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputAiComposeToneSlug) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputAiComposeToneSlug",
		ID:   InputAiComposeToneSlugTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Slug",
			SchemaName: "slug",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputAiComposeToneSlug) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputAiComposeToneSlug#1fa01357 as nil")
	}
	b.PutID(InputAiComposeToneSlugTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputAiComposeToneSlug) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputAiComposeToneSlug#1fa01357 as nil")
	}
	b.PutString(i.Slug)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputAiComposeToneSlug) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputAiComposeToneSlug#1fa01357 to nil")
	}
	if err := b.ConsumeID(InputAiComposeToneSlugTypeID); err != nil {
		return fmt.Errorf("unable to decode inputAiComposeToneSlug#1fa01357: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputAiComposeToneSlug) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputAiComposeToneSlug#1fa01357 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode inputAiComposeToneSlug#1fa01357: field slug: %w", err)
		}
		i.Slug = value
	}
	return nil
}

// GetSlug returns value of Slug field.
func (i *InputAiComposeToneSlug) GetSlug() (value string) {
	if i == nil {
		return
	}
	return i.Slug
}

// InputAiComposeToneClassName is schema name of InputAiComposeToneClass.
const InputAiComposeToneClassName = "InputAiComposeTone"

// InputAiComposeToneClass represents InputAiComposeTone generic type.
//
// See https://core.telegram.org/type/InputAiComposeTone for reference.
//
// Example:
//
//	g, err := tg.DecodeInputAiComposeTone(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.InputAiComposeToneDefault: // inputAiComposeToneDefault#1fe9a9bf
//	case *tg.InputAiComposeToneID: // inputAiComposeToneID#773c080
//	case *tg.InputAiComposeToneSlug: // inputAiComposeToneSlug#1fa01357
//	default: panic(v)
//	}
type InputAiComposeToneClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() InputAiComposeToneClass

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

// DecodeInputAiComposeTone implements binary de-serialization for InputAiComposeToneClass.
func DecodeInputAiComposeTone(buf *bin.Buffer) (InputAiComposeToneClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case InputAiComposeToneDefaultTypeID:
		// Decoding inputAiComposeToneDefault#1fe9a9bf.
		v := InputAiComposeToneDefault{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputAiComposeToneClass: %w", err)
		}
		return &v, nil
	case InputAiComposeToneIDTypeID:
		// Decoding inputAiComposeToneID#773c080.
		v := InputAiComposeToneID{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputAiComposeToneClass: %w", err)
		}
		return &v, nil
	case InputAiComposeToneSlugTypeID:
		// Decoding inputAiComposeToneSlug#1fa01357.
		v := InputAiComposeToneSlug{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputAiComposeToneClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode InputAiComposeToneClass: %w", bin.NewUnexpectedID(id))
	}
}

// InputAiComposeTone boxes the InputAiComposeToneClass providing a helper.
type InputAiComposeToneBox struct {
	InputAiComposeTone InputAiComposeToneClass
}

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

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