// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// PaymentsGetStarsRevenueAdsAccountURLRequest represents TL type `payments.getStarsRevenueAdsAccountUrl#d1d7efc5`.
// Returns a URL for a Telegram Ad platform account that can be used to set up
// advertisements for channel/bot in peer, paid using the Telegram Stars owned by the
// specified peer, see here »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/stars#paying-for-ads
//
// See https://core.telegram.org/method/payments.getStarsRevenueAdsAccountUrl for reference.
type PaymentsGetStarsRevenueAdsAccountURLRequest struct {
	// Channel or bot that owns the stars.
	Peer InputPeerClass
}

// PaymentsGetStarsRevenueAdsAccountURLRequestTypeID is TL type id of PaymentsGetStarsRevenueAdsAccountURLRequest.
const PaymentsGetStarsRevenueAdsAccountURLRequestTypeID = 0xd1d7efc5

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

func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Peer == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetStarsRevenueAdsAccountURLRequest from given interface.
func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
}) {
	g.Peer = from.GetPeer()
}

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

// TypeName returns name of type in TL schema.
func (*PaymentsGetStarsRevenueAdsAccountURLRequest) TypeName() string {
	return "payments.getStarsRevenueAdsAccountUrl"
}

// TypeInfo returns info about TL type.
func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.getStarsRevenueAdsAccountUrl",
		ID:   PaymentsGetStarsRevenueAdsAccountURLRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarsRevenueAdsAccountUrl#d1d7efc5 as nil")
	}
	b.PutID(PaymentsGetStarsRevenueAdsAccountURLRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarsRevenueAdsAccountUrl#d1d7efc5 as nil")
	}
	if g.Peer == nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueAdsAccountUrl#d1d7efc5: field peer is nil")
	}
	if err := g.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.getStarsRevenueAdsAccountUrl#d1d7efc5: field peer: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getStarsRevenueAdsAccountUrl#d1d7efc5 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.getStarsRevenueAdsAccountUrl#d1d7efc5: field peer: %w", err)
		}
		g.Peer = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (g *PaymentsGetStarsRevenueAdsAccountURLRequest) GetPeer() (value InputPeerClass) {
	if g == nil {
		return
	}
	return g.Peer
}

// PaymentsGetStarsRevenueAdsAccountURL invokes method payments.getStarsRevenueAdsAccountUrl#d1d7efc5 returning error if any.
// Returns a URL for a Telegram Ad platform account that can be used to set up
// advertisements for channel/bot in peer, paid using the Telegram Stars owned by the
// specified peer, see here »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/stars#paying-for-ads
//
// Possible errors:
//
//	403 CHAT_WRITE_FORBIDDEN: You can't write in this chat.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/payments.getStarsRevenueAdsAccountUrl for reference.
func (c *Client) PaymentsGetStarsRevenueAdsAccountURL(ctx context.Context, peer InputPeerClass) (*PaymentsStarsRevenueAdsAccountURL, error) {
	var result PaymentsStarsRevenueAdsAccountURL

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