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

// AicomposeGetToneRequest represents TL type `aicompose.getTone#b2e8ba03`.
//
// See https://core.telegram.org/method/aicompose.getTone for reference.
type AicomposeGetToneRequest struct {
	// Tone field of AicomposeGetToneRequest.
	Tone InputAiComposeToneClass
}

// AicomposeGetToneRequestTypeID is TL type id of AicomposeGetToneRequest.
const AicomposeGetToneRequestTypeID = 0xb2e8ba03

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

func (g *AicomposeGetToneRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Tone == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AicomposeGetToneRequest from given interface.
func (g *AicomposeGetToneRequest) FillFrom(from interface {
	GetTone() (value InputAiComposeToneClass)
}) {
	g.Tone = from.GetTone()
}

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

// TypeName returns name of type in TL schema.
func (*AicomposeGetToneRequest) TypeName() string {
	return "aicompose.getTone"
}

// TypeInfo returns info about TL type.
func (g *AicomposeGetToneRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "aicompose.getTone",
		ID:   AicomposeGetToneRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Tone",
			SchemaName: "tone",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *AicomposeGetToneRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode aicompose.getTone#b2e8ba03 as nil")
	}
	b.PutID(AicomposeGetToneRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *AicomposeGetToneRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode aicompose.getTone#b2e8ba03 as nil")
	}
	if g.Tone == nil {
		return fmt.Errorf("unable to encode aicompose.getTone#b2e8ba03: field tone is nil")
	}
	if err := g.Tone.Encode(b); err != nil {
		return fmt.Errorf("unable to encode aicompose.getTone#b2e8ba03: field tone: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *AicomposeGetToneRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode aicompose.getTone#b2e8ba03 to nil")
	}
	if err := b.ConsumeID(AicomposeGetToneRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode aicompose.getTone#b2e8ba03: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *AicomposeGetToneRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode aicompose.getTone#b2e8ba03 to nil")
	}
	{
		value, err := DecodeInputAiComposeTone(b)
		if err != nil {
			return fmt.Errorf("unable to decode aicompose.getTone#b2e8ba03: field tone: %w", err)
		}
		g.Tone = value
	}
	return nil
}

// GetTone returns value of Tone field.
func (g *AicomposeGetToneRequest) GetTone() (value InputAiComposeToneClass) {
	if g == nil {
		return
	}
	return g.Tone
}

// AicomposeGetTone invokes method aicompose.getTone#b2e8ba03 returning error if any.
//
// See https://core.telegram.org/method/aicompose.getTone for reference.
func (c *Client) AicomposeGetTone(ctx context.Context, tone InputAiComposeToneClass) (AicomposeTonesClass, error) {
	var result AicomposeTonesBox

	request := &AicomposeGetToneRequest{
		Tone: tone,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return result.Tones, nil
}
