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

// MessagesGetFutureChatCreatorAfterLeaveRequest represents TL type `messages.getFutureChatCreatorAfterLeave#3b7d0ea6`.
//
// See https://core.telegram.org/method/messages.getFutureChatCreatorAfterLeave for reference.
type MessagesGetFutureChatCreatorAfterLeaveRequest struct {
	// Peer field of MessagesGetFutureChatCreatorAfterLeaveRequest.
	Peer InputPeerClass
}

// MessagesGetFutureChatCreatorAfterLeaveRequestTypeID is TL type id of MessagesGetFutureChatCreatorAfterLeaveRequest.
const MessagesGetFutureChatCreatorAfterLeaveRequestTypeID = 0x3b7d0ea6

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

func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Peer == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesGetFutureChatCreatorAfterLeaveRequest from given interface.
func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
}) {
	g.Peer = from.GetPeer()
}

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

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

// TypeInfo returns info about TL type.
func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.getFutureChatCreatorAfterLeave",
		ID:   MessagesGetFutureChatCreatorAfterLeaveRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getFutureChatCreatorAfterLeave#3b7d0ea6 as nil")
	}
	b.PutID(MessagesGetFutureChatCreatorAfterLeaveRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getFutureChatCreatorAfterLeave#3b7d0ea6 as nil")
	}
	if g.Peer == nil {
		return fmt.Errorf("unable to encode messages.getFutureChatCreatorAfterLeave#3b7d0ea6: field peer is nil")
	}
	if err := g.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.getFutureChatCreatorAfterLeave#3b7d0ea6: field peer: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getFutureChatCreatorAfterLeave#3b7d0ea6 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.getFutureChatCreatorAfterLeave#3b7d0ea6: field peer: %w", err)
		}
		g.Peer = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (g *MessagesGetFutureChatCreatorAfterLeaveRequest) GetPeer() (value InputPeerClass) {
	if g == nil {
		return
	}
	return g.Peer
}

// MessagesGetFutureChatCreatorAfterLeave invokes method messages.getFutureChatCreatorAfterLeave#3b7d0ea6 returning error if any.
//
// See https://core.telegram.org/method/messages.getFutureChatCreatorAfterLeave for reference.
func (c *Client) MessagesGetFutureChatCreatorAfterLeave(ctx context.Context, peer InputPeerClass) (UserClass, error) {
	var result UserBox

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