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

// AiComposeToneExample represents TL type `aiComposeToneExample#f1d628ec`.
//
// See https://core.telegram.org/constructor/aiComposeToneExample for reference.
type AiComposeToneExample struct {
	// From field of AiComposeToneExample.
	From TextWithEntities
	// To field of AiComposeToneExample.
	To TextWithEntities
}

// AiComposeToneExampleTypeID is TL type id of AiComposeToneExample.
const AiComposeToneExampleTypeID = 0xf1d628ec

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

func (a *AiComposeToneExample) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.From.Zero()) {
		return false
	}
	if !(a.To.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills AiComposeToneExample from given interface.
func (a *AiComposeToneExample) FillFrom(from interface {
	GetFrom() (value TextWithEntities)
	GetTo() (value TextWithEntities)
}) {
	a.From = from.GetFrom()
	a.To = from.GetTo()
}

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

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

// TypeInfo returns info about TL type.
func (a *AiComposeToneExample) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "aiComposeToneExample",
		ID:   AiComposeToneExampleTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "From",
			SchemaName: "from",
		},
		{
			Name:       "To",
			SchemaName: "to",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AiComposeToneExample) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode aiComposeToneExample#f1d628ec as nil")
	}
	b.PutID(AiComposeToneExampleTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AiComposeToneExample) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode aiComposeToneExample#f1d628ec as nil")
	}
	if err := a.From.Encode(b); err != nil {
		return fmt.Errorf("unable to encode aiComposeToneExample#f1d628ec: field from: %w", err)
	}
	if err := a.To.Encode(b); err != nil {
		return fmt.Errorf("unable to encode aiComposeToneExample#f1d628ec: field to: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (a *AiComposeToneExample) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode aiComposeToneExample#f1d628ec to nil")
	}
	{
		if err := a.From.Decode(b); err != nil {
			return fmt.Errorf("unable to decode aiComposeToneExample#f1d628ec: field from: %w", err)
		}
	}
	{
		if err := a.To.Decode(b); err != nil {
			return fmt.Errorf("unable to decode aiComposeToneExample#f1d628ec: field to: %w", err)
		}
	}
	return nil
}

// GetFrom returns value of From field.
func (a *AiComposeToneExample) GetFrom() (value TextWithEntities) {
	if a == nil {
		return
	}
	return a.From
}

// GetTo returns value of To field.
func (a *AiComposeToneExample) GetTo() (value TextWithEntities) {
	if a == nil {
		return
	}
	return a.To
}
