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

// ChannelsUpdatePaidMessagesPriceRequest represents TL type `channels.updatePaidMessagesPrice#4b12327b`.
// Enable or disable paid messages »¹ in this supergroup² or monoforum³.
// Also used to enable or disable monoforums aka direct messages in a channel¹.
// Note that passing the ID of the monoforum itself to channel will return a
// CHANNEL_MONOFORUM_UNSUPPORTED error: pass the ID of the associated channel to edit the
// settings of the associated monoforum, instead.
//
// Links:
//  1. https://core.telegram.org/api/paid-messages
//  2. https://core.telegram.org/api/channel
//  3. https://core.telegram.org/api/monoforum
//  4. https://core.telegram.org/api/monoforum
//
// See https://core.telegram.org/method/channels.updatePaidMessagesPrice for reference.
type ChannelsUpdatePaidMessagesPriceRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Only usable for channels, enables or disables the associated monoforum aka direct
	// messages¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/monoforum
	BroadcastMessagesAllowed bool
	// Pass the supergroup ID for supergroups and the ID of the channel¹ to modify the
	// setting in the associated monoforum.
	//
	// Links:
	//  1) https://core.telegram.org/api/channel
	Channel InputChannelClass
	// Specifies the required amount of Telegram Stars¹ users must pay to send messages to
	// the supergroup or monoforum.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars
	SendPaidMessagesStars int64
}

// ChannelsUpdatePaidMessagesPriceRequestTypeID is TL type id of ChannelsUpdatePaidMessagesPriceRequest.
const ChannelsUpdatePaidMessagesPriceRequestTypeID = 0x4b12327b

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

func (u *ChannelsUpdatePaidMessagesPriceRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.Flags.Zero()) {
		return false
	}
	if !(u.BroadcastMessagesAllowed == false) {
		return false
	}
	if !(u.Channel == nil) {
		return false
	}
	if !(u.SendPaidMessagesStars == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsUpdatePaidMessagesPriceRequest from given interface.
func (u *ChannelsUpdatePaidMessagesPriceRequest) FillFrom(from interface {
	GetBroadcastMessagesAllowed() (value bool)
	GetChannel() (value InputChannelClass)
	GetSendPaidMessagesStars() (value int64)
}) {
	u.BroadcastMessagesAllowed = from.GetBroadcastMessagesAllowed()
	u.Channel = from.GetChannel()
	u.SendPaidMessagesStars = from.GetSendPaidMessagesStars()
}

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

// TypeName returns name of type in TL schema.
func (*ChannelsUpdatePaidMessagesPriceRequest) TypeName() string {
	return "channels.updatePaidMessagesPrice"
}

// TypeInfo returns info about TL type.
func (u *ChannelsUpdatePaidMessagesPriceRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "channels.updatePaidMessagesPrice",
		ID:   ChannelsUpdatePaidMessagesPriceRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BroadcastMessagesAllowed",
			SchemaName: "broadcast_messages_allowed",
			Null:       !u.Flags.Has(0),
		},
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
		{
			Name:       "SendPaidMessagesStars",
			SchemaName: "send_paid_messages_stars",
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (u *ChannelsUpdatePaidMessagesPriceRequest) SetFlags() {
	if !(u.BroadcastMessagesAllowed == false) {
		u.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func (u *ChannelsUpdatePaidMessagesPriceRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode channels.updatePaidMessagesPrice#4b12327b as nil")
	}
	b.PutID(ChannelsUpdatePaidMessagesPriceRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *ChannelsUpdatePaidMessagesPriceRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode channels.updatePaidMessagesPrice#4b12327b as nil")
	}
	u.SetFlags()
	if err := u.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.updatePaidMessagesPrice#4b12327b: field flags: %w", err)
	}
	if u.Channel == nil {
		return fmt.Errorf("unable to encode channels.updatePaidMessagesPrice#4b12327b: field channel is nil")
	}
	if err := u.Channel.Encode(b); err != nil {
		return fmt.Errorf("unable to encode channels.updatePaidMessagesPrice#4b12327b: field channel: %w", err)
	}
	b.PutLong(u.SendPaidMessagesStars)
	return nil
}

// Decode implements bin.Decoder.
func (u *ChannelsUpdatePaidMessagesPriceRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode channels.updatePaidMessagesPrice#4b12327b to nil")
	}
	if err := b.ConsumeID(ChannelsUpdatePaidMessagesPriceRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode channels.updatePaidMessagesPrice#4b12327b: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *ChannelsUpdatePaidMessagesPriceRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode channels.updatePaidMessagesPrice#4b12327b to nil")
	}
	{
		if err := u.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode channels.updatePaidMessagesPrice#4b12327b: field flags: %w", err)
		}
	}
	u.BroadcastMessagesAllowed = u.Flags.Has(0)
	{
		value, err := DecodeInputChannel(b)
		if err != nil {
			return fmt.Errorf("unable to decode channels.updatePaidMessagesPrice#4b12327b: field channel: %w", err)
		}
		u.Channel = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode channels.updatePaidMessagesPrice#4b12327b: field send_paid_messages_stars: %w", err)
		}
		u.SendPaidMessagesStars = value
	}
	return nil
}

// SetBroadcastMessagesAllowed sets value of BroadcastMessagesAllowed conditional field.
func (u *ChannelsUpdatePaidMessagesPriceRequest) SetBroadcastMessagesAllowed(value bool) {
	if value {
		u.Flags.Set(0)
		u.BroadcastMessagesAllowed = true
	} else {
		u.Flags.Unset(0)
		u.BroadcastMessagesAllowed = false
	}
}

// GetBroadcastMessagesAllowed returns value of BroadcastMessagesAllowed conditional field.
func (u *ChannelsUpdatePaidMessagesPriceRequest) GetBroadcastMessagesAllowed() (value bool) {
	if u == nil {
		return
	}
	return u.Flags.Has(0)
}

// GetChannel returns value of Channel field.
func (u *ChannelsUpdatePaidMessagesPriceRequest) GetChannel() (value InputChannelClass) {
	if u == nil {
		return
	}
	return u.Channel
}

// GetSendPaidMessagesStars returns value of SendPaidMessagesStars field.
func (u *ChannelsUpdatePaidMessagesPriceRequest) GetSendPaidMessagesStars() (value int64) {
	if u == nil {
		return
	}
	return u.SendPaidMessagesStars
}

// GetChannelAsNotEmpty returns mapped value of Channel field.
func (u *ChannelsUpdatePaidMessagesPriceRequest) GetChannelAsNotEmpty() (NotEmptyInputChannel, bool) {
	return u.Channel.AsNotEmpty()
}

// ChannelsUpdatePaidMessagesPrice invokes method channels.updatePaidMessagesPrice#4b12327b returning error if any.
// Enable or disable paid messages »¹ in this supergroup² or monoforum³.
// Also used to enable or disable monoforums aka direct messages in a channel¹.
// Note that passing the ID of the monoforum itself to channel will return a
// CHANNEL_MONOFORUM_UNSUPPORTED error: pass the ID of the associated channel to edit the
// settings of the associated monoforum, instead.
//
// Links:
//  1. https://core.telegram.org/api/paid-messages
//  2. https://core.telegram.org/api/channel
//  3. https://core.telegram.org/api/monoforum
//  4. https://core.telegram.org/api/monoforum
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHANNEL_MONOFORUM_UNSUPPORTED: Monoforums do not support this feature.
//	400 CHAT_NOT_MODIFIED: No changes were made to chat information because the new information you passed is identical to the current information.
//	400 STARS_AMOUNT_INVALID: The specified amount in stars is invalid.
//
// See https://core.telegram.org/method/channels.updatePaidMessagesPrice for reference.
func (c *Client) ChannelsUpdatePaidMessagesPrice(ctx context.Context, request *ChannelsUpdatePaidMessagesPriceRequest) (UpdatesClass, error) {
	var result UpdatesBox

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