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

// AicomposeGetToneExampleRequest represents TL type `aicompose.getToneExample#d1b4ab14`.
//
// See https://core.telegram.org/method/aicompose.getToneExample for reference.
type AicomposeGetToneExampleRequest struct {
	// Tone field of AicomposeGetToneExampleRequest.
	Tone InputAiComposeToneClass
	// Num field of AicomposeGetToneExampleRequest.
	Num int
}

// AicomposeGetToneExampleRequestTypeID is TL type id of AicomposeGetToneExampleRequest.
const AicomposeGetToneExampleRequestTypeID = 0xd1b4ab14

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

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

	return true
}

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

// FillFrom fills AicomposeGetToneExampleRequest from given interface.
func (g *AicomposeGetToneExampleRequest) FillFrom(from interface {
	GetTone() (value InputAiComposeToneClass)
	GetNum() (value int)
}) {
	g.Tone = from.GetTone()
	g.Num = from.GetNum()
}

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

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

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

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

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

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

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

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

// GetNum returns value of Num field.
func (g *AicomposeGetToneExampleRequest) GetNum() (value int) {
	if g == nil {
		return
	}
	return g.Num
}

// AicomposeGetToneExample invokes method aicompose.getToneExample#d1b4ab14 returning error if any.
//
// See https://core.telegram.org/method/aicompose.getToneExample for reference.
func (c *Client) AicomposeGetToneExample(ctx context.Context, request *AicomposeGetToneExampleRequest) (*AiComposeToneExample, error) {
	var result AiComposeToneExample

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