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

// ClickPremiumSubscriptionButtonRequest represents TL type `clickPremiumSubscriptionButton#e9fca306`.
type ClickPremiumSubscriptionButtonRequest struct {
}

// ClickPremiumSubscriptionButtonRequestTypeID is TL type id of ClickPremiumSubscriptionButtonRequest.
const ClickPremiumSubscriptionButtonRequestTypeID = 0xe9fca306

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

func (c *ClickPremiumSubscriptionButtonRequest) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (c *ClickPremiumSubscriptionButtonRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clickPremiumSubscriptionButton#e9fca306 as nil")
	}
	b.PutID(ClickPremiumSubscriptionButtonRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ClickPremiumSubscriptionButtonRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode clickPremiumSubscriptionButton#e9fca306 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *ClickPremiumSubscriptionButtonRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clickPremiumSubscriptionButton#e9fca306 to nil")
	}
	if err := b.ConsumeID(ClickPremiumSubscriptionButtonRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode clickPremiumSubscriptionButton#e9fca306: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ClickPremiumSubscriptionButtonRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode clickPremiumSubscriptionButton#e9fca306 to nil")
	}
	return nil
}

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

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *ClickPremiumSubscriptionButtonRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode clickPremiumSubscriptionButton#e9fca306 to nil")
	}

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

// ClickPremiumSubscriptionButton invokes method clickPremiumSubscriptionButton#e9fca306 returning error if any.
func (c *Client) ClickPremiumSubscriptionButton(ctx context.Context) error {
	var ok Ok

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