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

// GetImportedContactCountRequest represents TL type `getImportedContactCount#d8e11a26`.
type GetImportedContactCountRequest struct {
}

// GetImportedContactCountRequestTypeID is TL type id of GetImportedContactCountRequest.
const GetImportedContactCountRequestTypeID = 0xd8e11a26

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetImportedContactCountRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getImportedContactCount#d8e11a26 as nil")
	}
	b.PutID(GetImportedContactCountRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetImportedContactCountRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getImportedContactCount#d8e11a26 as nil")
	}
	b.ObjStart()
	b.PutID("getImportedContactCount")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getImportedContactCount"); err != nil {
				return fmt.Errorf("unable to decode getImportedContactCount#d8e11a26: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetImportedContactCount invokes method getImportedContactCount#d8e11a26 returning error if any.
func (c *Client) GetImportedContactCount(ctx context.Context) (*Count, error) {
	var result Count

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