// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// MessagesGetMessageReadParticipantsRequest represents TL type `messages.getMessageReadParticipants#31c1c44f`.
// Get which users read a specific message: only available for groups and supergroups
// with less than chat_read_mark_size_threshold members¹, read receipts will be stored
// for chat_read_mark_expire_period seconds after the message was sent², see client
// configuration for more info »³.
//
// Links:
//  1. https://core.telegram.org/api/config#chat-read-mark-size-threshold
//  2. https://core.telegram.org/api/config#chat-read-mark-expire-period
//  3. https://core.telegram.org/api/config#client-configuration
//
// See https://core.telegram.org/method/messages.getMessageReadParticipants for reference.
type MessagesGetMessageReadParticipantsRequest struct {
	// Dialog
	Peer InputPeerClass
	// Message ID
	MsgID int
}

// MessagesGetMessageReadParticipantsRequestTypeID is TL type id of MessagesGetMessageReadParticipantsRequest.
const MessagesGetMessageReadParticipantsRequestTypeID = 0x31c1c44f

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

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

	return true
}

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

// FillFrom fills MessagesGetMessageReadParticipantsRequest from given interface.
func (g *MessagesGetMessageReadParticipantsRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetMsgID() (value int)
}) {
	g.Peer = from.GetPeer()
	g.MsgID = from.GetMsgID()
}

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

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

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

// Encode implements bin.Encoder.
func (g *MessagesGetMessageReadParticipantsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getMessageReadParticipants#31c1c44f as nil")
	}
	b.PutID(MessagesGetMessageReadParticipantsRequestTypeID)
	return g.EncodeBare(b)
}

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

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

// DecodeBare implements bin.BareDecoder.
func (g *MessagesGetMessageReadParticipantsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getMessageReadParticipants#31c1c44f to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.getMessageReadParticipants#31c1c44f: field peer: %w", err)
		}
		g.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.getMessageReadParticipants#31c1c44f: field msg_id: %w", err)
		}
		g.MsgID = value
	}
	return nil
}

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

// GetMsgID returns value of MsgID field.
func (g *MessagesGetMessageReadParticipantsRequest) GetMsgID() (value int) {
	if g == nil {
		return
	}
	return g.MsgID
}

// MessagesGetMessageReadParticipants invokes method messages.getMessageReadParticipants#31c1c44f returning error if any.
// Get which users read a specific message: only available for groups and supergroups
// with less than chat_read_mark_size_threshold members¹, read receipts will be stored
// for chat_read_mark_expire_period seconds after the message was sent², see client
// configuration for more info »³.
//
// Links:
//  1. https://core.telegram.org/api/config#chat-read-mark-size-threshold
//  2. https://core.telegram.org/api/config#chat-read-mark-expire-period
//  3. https://core.telegram.org/api/config#client-configuration
//
// Possible errors:
//
//	400 CHAT_TOO_BIG: This method is not available for groups with more than chat_read_mark_size_threshold members, see client configuration ».
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 MSG_TOO_OLD: chat_read_mark_expire_period seconds have passed since the message was sent, read receipts were deleted.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/messages.getMessageReadParticipants for reference.
func (c *Client) MessagesGetMessageReadParticipants(ctx context.Context, request *MessagesGetMessageReadParticipantsRequest) ([]ReadParticipantDate, error) {
	var result ReadParticipantDateVector

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