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

// ClearImportedContactsRequest represents TL type `clearImportedContacts#33d39142`.
type ClearImportedContactsRequest struct {
}

// ClearImportedContactsRequestTypeID is TL type id of ClearImportedContactsRequest.
const ClearImportedContactsRequestTypeID = 0x33d39142

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

func (c *ClearImportedContactsRequest) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *ClearImportedContactsRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clearImportedContacts#33d39142 as nil")
	}
	b.PutID(ClearImportedContactsRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ClearImportedContactsRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clearImportedContacts#33d39142 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *ClearImportedContactsRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clearImportedContacts#33d39142 to nil")
	}
	if err := b.ConsumeID(ClearImportedContactsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode clearImportedContacts#33d39142: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ClearImportedContactsRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clearImportedContacts#33d39142 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ClearImportedContactsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode clearImportedContacts#33d39142 as nil")
	}
	b.ObjStart()
	b.PutID("clearImportedContacts")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *ClearImportedContactsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode clearImportedContacts#33d39142 to nil")
	}

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

// ClearImportedContacts invokes method clearImportedContacts#33d39142 returning error if any.
func (c *Client) ClearImportedContacts(ctx context.Context) error {
	var ok Ok

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