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

// GetInactiveSupergroupChatsRequest represents TL type `getInactiveSupergroupChats#d8cbf9b5`.
type GetInactiveSupergroupChatsRequest struct {
}

// GetInactiveSupergroupChatsRequestTypeID is TL type id of GetInactiveSupergroupChatsRequest.
const GetInactiveSupergroupChatsRequestTypeID = 0xd8cbf9b5

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetInactiveSupergroupChatsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getInactiveSupergroupChats#d8cbf9b5 as nil")
	}
	b.PutID(GetInactiveSupergroupChatsRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetInactiveSupergroupChats invokes method getInactiveSupergroupChats#d8cbf9b5 returning error if any.
func (c *Client) GetInactiveSupergroupChats(ctx context.Context) (*Chats, error) {
	var result Chats

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