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

// PaymentsConnectStarRefBotRequest represents TL type `payments.connectStarRefBot#7ed5348a`.
// Join a bot's affiliate program, becoming an affiliate »¹
//
// Links:
//  1. https://core.telegram.org/api/bots/referrals#becoming-an-affiliate
//
// See https://core.telegram.org/method/payments.connectStarRefBot for reference.
type PaymentsConnectStarRefBotRequest struct {
	// The peer that will become the affiliate: star commissions will be transferred to this
	// peer's star balance.
	Peer InputPeerClass
	// The bot that offers the affiliate program
	Bot InputUserClass
}

// PaymentsConnectStarRefBotRequestTypeID is TL type id of PaymentsConnectStarRefBotRequest.
const PaymentsConnectStarRefBotRequestTypeID = 0x7ed5348a

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

func (c *PaymentsConnectStarRefBotRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Peer == nil) {
		return false
	}
	if !(c.Bot == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsConnectStarRefBotRequest from given interface.
func (c *PaymentsConnectStarRefBotRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetBot() (value InputUserClass)
}) {
	c.Peer = from.GetPeer()
	c.Bot = from.GetBot()
}

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

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

// TypeInfo returns info about TL type.
func (c *PaymentsConnectStarRefBotRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.connectStarRefBot",
		ID:   PaymentsConnectStarRefBotRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *PaymentsConnectStarRefBotRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.connectStarRefBot#7ed5348a as nil")
	}
	b.PutID(PaymentsConnectStarRefBotRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *PaymentsConnectStarRefBotRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode payments.connectStarRefBot#7ed5348a as nil")
	}
	if c.Peer == nil {
		return fmt.Errorf("unable to encode payments.connectStarRefBot#7ed5348a: field peer is nil")
	}
	if err := c.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.connectStarRefBot#7ed5348a: field peer: %w", err)
	}
	if c.Bot == nil {
		return fmt.Errorf("unable to encode payments.connectStarRefBot#7ed5348a: field bot is nil")
	}
	if err := c.Bot.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.connectStarRefBot#7ed5348a: field bot: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *PaymentsConnectStarRefBotRequest) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.connectStarRefBot#7ed5348a to nil")
	}
	if err := b.ConsumeID(PaymentsConnectStarRefBotRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.connectStarRefBot#7ed5348a: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *PaymentsConnectStarRefBotRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode payments.connectStarRefBot#7ed5348a to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.connectStarRefBot#7ed5348a: field peer: %w", err)
		}
		c.Peer = value
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.connectStarRefBot#7ed5348a: field bot: %w", err)
		}
		c.Bot = value
	}
	return nil
}

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

// GetBot returns value of Bot field.
func (c *PaymentsConnectStarRefBotRequest) GetBot() (value InputUserClass) {
	if c == nil {
		return
	}
	return c.Bot
}

// PaymentsConnectStarRefBot invokes method payments.connectStarRefBot#7ed5348a returning error if any.
// Join a bot's affiliate program, becoming an affiliate »¹
//
// Links:
//  1. https://core.telegram.org/api/bots/referrals#becoming-an-affiliate
//
// See https://core.telegram.org/method/payments.connectStarRefBot for reference.
func (c *Client) PaymentsConnectStarRefBot(ctx context.Context, request *PaymentsConnectStarRefBotRequest) (*PaymentsConnectedStarRefBots, error) {
	var result PaymentsConnectedStarRefBots

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