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

// GetPremiumStateRequest represents TL type `getPremiumState#278e3ae2`.
type GetPremiumStateRequest struct {
}

// GetPremiumStateRequestTypeID is TL type id of GetPremiumStateRequest.
const GetPremiumStateRequestTypeID = 0x278e3ae2

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (g *GetPremiumStateRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPremiumState#278e3ae2 as nil")
	}
	b.PutID(GetPremiumStateRequestTypeID)
	return g.EncodeBare(b)
}

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

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

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

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

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

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

// GetPremiumState invokes method getPremiumState#278e3ae2 returning error if any.
func (c *Client) GetPremiumState(ctx context.Context) (*PremiumState, error) {
	var result PremiumState

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