// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// PhoneGetGroupCallStreamRtmpURLRequest represents TL type `phone.getGroupCallStreamRtmpUrl#deb3abbf`.
// Get RTMP URL and stream key for RTMP livestreams. Can be used even before creating the
// actual RTMP livestream with phone.createGroupCall¹ (the rtmp_stream flag must be set).
//
// Links:
//  1. https://core.telegram.org/method/phone.createGroupCall
//
// See https://core.telegram.org/method/phone.getGroupCallStreamRtmpUrl for reference.
type PhoneGetGroupCallStreamRtmpURLRequest struct {
	// Peer to livestream into
	Peer InputPeerClass
	// Whether to revoke the previous stream key or simply return the existing one
	Revoke bool
}

// PhoneGetGroupCallStreamRtmpURLRequestTypeID is TL type id of PhoneGetGroupCallStreamRtmpURLRequest.
const PhoneGetGroupCallStreamRtmpURLRequestTypeID = 0xdeb3abbf

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

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

	return true
}

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

// FillFrom fills PhoneGetGroupCallStreamRtmpURLRequest from given interface.
func (g *PhoneGetGroupCallStreamRtmpURLRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetRevoke() (value bool)
}) {
	g.Peer = from.GetPeer()
	g.Revoke = from.GetRevoke()
}

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

// TypeName returns name of type in TL schema.
func (*PhoneGetGroupCallStreamRtmpURLRequest) TypeName() string {
	return "phone.getGroupCallStreamRtmpUrl"
}

// TypeInfo returns info about TL type.
func (g *PhoneGetGroupCallStreamRtmpURLRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.getGroupCallStreamRtmpUrl",
		ID:   PhoneGetGroupCallStreamRtmpURLRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Revoke",
			SchemaName: "revoke",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PhoneGetGroupCallStreamRtmpURLRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode phone.getGroupCallStreamRtmpUrl#deb3abbf as nil")
	}
	b.PutID(PhoneGetGroupCallStreamRtmpURLRequestTypeID)
	return g.EncodeBare(b)
}

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

// Decode implements bin.Decoder.
func (g *PhoneGetGroupCallStreamRtmpURLRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode phone.getGroupCallStreamRtmpUrl#deb3abbf to nil")
	}
	if err := b.ConsumeID(PhoneGetGroupCallStreamRtmpURLRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode phone.getGroupCallStreamRtmpUrl#deb3abbf: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *PhoneGetGroupCallStreamRtmpURLRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode phone.getGroupCallStreamRtmpUrl#deb3abbf to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode phone.getGroupCallStreamRtmpUrl#deb3abbf: field peer: %w", err)
		}
		g.Peer = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode phone.getGroupCallStreamRtmpUrl#deb3abbf: field revoke: %w", err)
		}
		g.Revoke = value
	}
	return nil
}

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

// GetRevoke returns value of Revoke field.
func (g *PhoneGetGroupCallStreamRtmpURLRequest) GetRevoke() (value bool) {
	if g == nil {
		return
	}
	return g.Revoke
}

// PhoneGetGroupCallStreamRtmpURL invokes method phone.getGroupCallStreamRtmpUrl#deb3abbf returning error if any.
// Get RTMP URL and stream key for RTMP livestreams. Can be used even before creating the
// actual RTMP livestream with phone.createGroupCall¹ (the rtmp_stream flag must be set).
//
// Links:
//  1. https://core.telegram.org/method/phone.createGroupCall
//
// Possible errors:
//
//	400 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//
// See https://core.telegram.org/method/phone.getGroupCallStreamRtmpUrl for reference.
func (c *Client) PhoneGetGroupCallStreamRtmpURL(ctx context.Context, request *PhoneGetGroupCallStreamRtmpURLRequest) (*PhoneGroupCallStreamRtmpURL, error) {
	var result PhoneGroupCallStreamRtmpURL

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