// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// GetPreparedInlineMessageRequest represents TL type `getPreparedInlineMessage#fb0ac74b`.
type GetPreparedInlineMessageRequest struct {
	// Identifier of the bot that created the message
	BotUserID int64
	// Identifier of the prepared message
	PreparedMessageID string
}

// GetPreparedInlineMessageRequestTypeID is TL type id of GetPreparedInlineMessageRequest.
const GetPreparedInlineMessageRequestTypeID = 0xfb0ac74b

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

func (g *GetPreparedInlineMessageRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.BotUserID == 0) {
		return false
	}
	if !(g.PreparedMessageID == "") {
		return false
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*GetPreparedInlineMessageRequest) TypeName() string {
	return "getPreparedInlineMessage"
}

// TypeInfo returns info about TL type.
func (g *GetPreparedInlineMessageRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPreparedInlineMessage",
		ID:   GetPreparedInlineMessageRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "PreparedMessageID",
			SchemaName: "prepared_message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPreparedInlineMessageRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPreparedInlineMessage#fb0ac74b as nil")
	}
	b.PutID(GetPreparedInlineMessageRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPreparedInlineMessageRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPreparedInlineMessage#fb0ac74b as nil")
	}
	b.PutInt53(g.BotUserID)
	b.PutString(g.PreparedMessageID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetPreparedInlineMessageRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPreparedInlineMessage#fb0ac74b to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode getPreparedInlineMessage#fb0ac74b: field bot_user_id: %w", err)
		}
		g.BotUserID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getPreparedInlineMessage#fb0ac74b: field prepared_message_id: %w", err)
		}
		g.PreparedMessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPreparedInlineMessageRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPreparedInlineMessage#fb0ac74b as nil")
	}
	b.ObjStart()
	b.PutID("getPreparedInlineMessage")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(g.BotUserID)
	b.Comma()
	b.FieldStart("prepared_message_id")
	b.PutString(g.PreparedMessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetPreparedInlineMessageRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getPreparedInlineMessage#fb0ac74b to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getPreparedInlineMessage"); err != nil {
				return fmt.Errorf("unable to decode getPreparedInlineMessage#fb0ac74b: %w", err)
			}
		case "bot_user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode getPreparedInlineMessage#fb0ac74b: field bot_user_id: %w", err)
			}
			g.BotUserID = value
		case "prepared_message_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode getPreparedInlineMessage#fb0ac74b: field prepared_message_id: %w", err)
			}
			g.PreparedMessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBotUserID returns value of BotUserID field.
func (g *GetPreparedInlineMessageRequest) GetBotUserID() (value int64) {
	if g == nil {
		return
	}
	return g.BotUserID
}

// GetPreparedMessageID returns value of PreparedMessageID field.
func (g *GetPreparedInlineMessageRequest) GetPreparedMessageID() (value string) {
	if g == nil {
		return
	}
	return g.PreparedMessageID
}

// GetPreparedInlineMessage invokes method getPreparedInlineMessage#fb0ac74b returning error if any.
func (c *Client) GetPreparedInlineMessage(ctx context.Context, request *GetPreparedInlineMessageRequest) (*PreparedInlineMessage, error) {
	var result PreparedInlineMessage

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