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

// AicomposeGetTonesRequest represents TL type `aicompose.getTones#abd59201`.
//
// See https://core.telegram.org/method/aicompose.getTones for reference.
type AicomposeGetTonesRequest struct {
	// Hash field of AicomposeGetTonesRequest.
	Hash int64
}

// AicomposeGetTonesRequestTypeID is TL type id of AicomposeGetTonesRequest.
const AicomposeGetTonesRequestTypeID = 0xabd59201

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

func (g *AicomposeGetTonesRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills AicomposeGetTonesRequest from given interface.
func (g *AicomposeGetTonesRequest) FillFrom(from interface {
	GetHash() (value int64)
}) {
	g.Hash = from.GetHash()
}

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

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

// TypeInfo returns info about TL type.
func (g *AicomposeGetTonesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "aicompose.getTones",
		ID:   AicomposeGetTonesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return typ
}

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

// EncodeBare implements bin.BareEncoder.
func (g *AicomposeGetTonesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode aicompose.getTones#abd59201 as nil")
	}
	b.PutLong(g.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *AicomposeGetTonesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode aicompose.getTones#abd59201 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode aicompose.getTones#abd59201: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

// GetHash returns value of Hash field.
func (g *AicomposeGetTonesRequest) GetHash() (value int64) {
	if g == nil {
		return
	}
	return g.Hash
}

// AicomposeGetTones invokes method aicompose.getTones#abd59201 returning error if any.
//
// See https://core.telegram.org/method/aicompose.getTones for reference.
func (c *Client) AicomposeGetTones(ctx context.Context, hash int64) (AicomposeTonesClass, error) {
	var result AicomposeTonesBox

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