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

// ContactsGetStatusesRequest represents TL type `contacts.getStatuses#c4a353ee`.
// Use this method to obtain the online statuses of all contacts with an accessible
// Telegram account.
//
// See https://core.telegram.org/method/contacts.getStatuses for reference.
type ContactsGetStatusesRequest struct {
}

// ContactsGetStatusesRequestTypeID is TL type id of ContactsGetStatusesRequest.
const ContactsGetStatusesRequestTypeID = 0xc4a353ee

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

func (g *ContactsGetStatusesRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*ContactsGetStatusesRequest) TypeName() string {
	return "contacts.getStatuses"
}

// TypeInfo returns info about TL type.
func (g *ContactsGetStatusesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "contacts.getStatuses",
		ID:   ContactsGetStatusesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *ContactsGetStatusesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode contacts.getStatuses#c4a353ee as nil")
	}
	b.PutID(ContactsGetStatusesRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *ContactsGetStatusesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode contacts.getStatuses#c4a353ee as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *ContactsGetStatusesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode contacts.getStatuses#c4a353ee to nil")
	}
	return nil
}

// ContactsGetStatuses invokes method contacts.getStatuses#c4a353ee returning error if any.
// Use this method to obtain the online statuses of all contacts with an accessible
// Telegram account.
//
// See https://core.telegram.org/method/contacts.getStatuses for reference.
func (c *Client) ContactsGetStatuses(ctx context.Context) ([]ContactStatus, error) {
	var result ContactStatusVector

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