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

// GetNewChatPrivacySettingsRequest represents TL type `getNewChatPrivacySettings#b2cb4bb7`.
type GetNewChatPrivacySettingsRequest struct {
}

// GetNewChatPrivacySettingsRequestTypeID is TL type id of GetNewChatPrivacySettingsRequest.
const GetNewChatPrivacySettingsRequestTypeID = 0xb2cb4bb7

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetNewChatPrivacySettingsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getNewChatPrivacySettings#b2cb4bb7 as nil")
	}
	b.PutID(GetNewChatPrivacySettingsRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetNewChatPrivacySettings invokes method getNewChatPrivacySettings#b2cb4bb7 returning error if any.
func (c *Client) GetNewChatPrivacySettings(ctx context.Context) (*NewChatPrivacySettings, error) {
	var result NewChatPrivacySettings

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