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

// GetAuthorizationStateRequest represents TL type `getAuthorizationState#742dbe3d`.
type GetAuthorizationStateRequest struct {
}

// GetAuthorizationStateRequestTypeID is TL type id of GetAuthorizationStateRequest.
const GetAuthorizationStateRequestTypeID = 0x742dbe3d

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetAuthorizationStateRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getAuthorizationState#742dbe3d as nil")
	}
	b.PutID(GetAuthorizationStateRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetAuthorizationState invokes method getAuthorizationState#742dbe3d returning error if any.
func (c *Client) GetAuthorizationState(ctx context.Context) (AuthorizationStateClass, error) {
	var result AuthorizationStateBox

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