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

// LogOutRequest represents TL type `logOut#a1b5c41b`.
type LogOutRequest struct {
}

// LogOutRequestTypeID is TL type id of LogOutRequest.
const LogOutRequestTypeID = 0xa1b5c41b

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

func (l *LogOutRequest) Zero() bool {
	if l == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (l *LogOutRequest) Encode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode logOut#a1b5c41b as nil")
	}
	b.PutID(LogOutRequestTypeID)
	return l.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (l *LogOutRequest) EncodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't encode logOut#a1b5c41b as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (l *LogOutRequest) Decode(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode logOut#a1b5c41b to nil")
	}
	if err := b.ConsumeID(LogOutRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode logOut#a1b5c41b: %w", err)
	}
	return l.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (l *LogOutRequest) DecodeBare(b *bin.Buffer) error {
	if l == nil {
		return fmt.Errorf("can't decode logOut#a1b5c41b to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (l *LogOutRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if l == nil {
		return fmt.Errorf("can't decode logOut#a1b5c41b to nil")
	}

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

// LogOut invokes method logOut#a1b5c41b returning error if any.
func (c *Client) LogOut(ctx context.Context) error {
	var ok Ok

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