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

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

// AicomposeDeleteToneRequestTypeID is TL type id of AicomposeDeleteToneRequest.
const AicomposeDeleteToneRequestTypeID = 0xdd39316a

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

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

	return true
}

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

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

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

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

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

// Encode implements bin.Encoder.
func (d *AicomposeDeleteToneRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode aicompose.deleteTone#dd39316a as nil")
	}
	b.PutID(AicomposeDeleteToneRequestTypeID)
	return d.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (d *AicomposeDeleteToneRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode aicompose.deleteTone#dd39316a to nil")
	}
	if err := b.ConsumeID(AicomposeDeleteToneRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode aicompose.deleteTone#dd39316a: %w", err)
	}
	return d.DecodeBare(b)
}

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

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

// AicomposeDeleteTone invokes method aicompose.deleteTone#dd39316a returning error if any.
//
// See https://core.telegram.org/method/aicompose.deleteTone for reference.
func (c *Client) AicomposeDeleteTone(ctx context.Context, tone InputAiComposeToneClass) (bool, error) {
	var result BoolBox

	request := &AicomposeDeleteToneRequest{
		Tone: tone,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
