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

// MessagesGetAvailableEffectsRequest represents TL type `messages.getAvailableEffects#dea20a39`.
// Fetch the full list of usable animated message effects »¹.
//
// Links:
//  1. https://core.telegram.org/api/effects
//
// See https://core.telegram.org/method/messages.getAvailableEffects for reference.
type MessagesGetAvailableEffectsRequest struct {
	// Hash used for caching, for more info click here¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int
}

// MessagesGetAvailableEffectsRequestTypeID is TL type id of MessagesGetAvailableEffectsRequest.
const MessagesGetAvailableEffectsRequestTypeID = 0xdea20a39

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

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

	return true
}

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

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

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

// TypeName returns name of type in TL schema.
func (*MessagesGetAvailableEffectsRequest) TypeName() string {
	return "messages.getAvailableEffects"
}

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

// Encode implements bin.Encoder.
func (g *MessagesGetAvailableEffectsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getAvailableEffects#dea20a39 as nil")
	}
	b.PutID(MessagesGetAvailableEffectsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *MessagesGetAvailableEffectsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getAvailableEffects#dea20a39 as nil")
	}
	b.PutInt(g.Hash)
	return nil
}

// Decode implements bin.Decoder.
func (g *MessagesGetAvailableEffectsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getAvailableEffects#dea20a39 to nil")
	}
	if err := b.ConsumeID(MessagesGetAvailableEffectsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.getAvailableEffects#dea20a39: %w", err)
	}
	return g.DecodeBare(b)
}

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

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

// MessagesGetAvailableEffects invokes method messages.getAvailableEffects#dea20a39 returning error if any.
// Fetch the full list of usable animated message effects »¹.
//
// Links:
//  1. https://core.telegram.org/api/effects
//
// See https://core.telegram.org/method/messages.getAvailableEffects for reference.
func (c *Client) MessagesGetAvailableEffects(ctx context.Context, hash int) (MessagesAvailableEffectsClass, error) {
	var result MessagesAvailableEffectsBox

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