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

// PhoneSendConferenceCallBroadcastRequest represents TL type `phone.sendConferenceCallBroadcast#c6701900`.
// Broadcast a blockchain block to all members of a conference call, see here »¹ for
// more info.
//
// Links:
//  1. https://core.telegram.org/api/end-to-end/group-calls
//
// See https://core.telegram.org/method/phone.sendConferenceCallBroadcast for reference.
type PhoneSendConferenceCallBroadcastRequest struct {
	// The conference where to broadcast the block.
	Call InputGroupCallClass
	// The block to broadcast.
	Block []byte
}

// PhoneSendConferenceCallBroadcastRequestTypeID is TL type id of PhoneSendConferenceCallBroadcastRequest.
const PhoneSendConferenceCallBroadcastRequestTypeID = 0xc6701900

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

func (s *PhoneSendConferenceCallBroadcastRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Call == nil) {
		return false
	}
	if !(s.Block == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneSendConferenceCallBroadcastRequest from given interface.
func (s *PhoneSendConferenceCallBroadcastRequest) FillFrom(from interface {
	GetCall() (value InputGroupCallClass)
	GetBlock() (value []byte)
}) {
	s.Call = from.GetCall()
	s.Block = from.GetBlock()
}

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

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

// TypeInfo returns info about TL type.
func (s *PhoneSendConferenceCallBroadcastRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.sendConferenceCallBroadcast",
		ID:   PhoneSendConferenceCallBroadcastRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Call",
			SchemaName: "call",
		},
		{
			Name:       "Block",
			SchemaName: "block",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *PhoneSendConferenceCallBroadcastRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode phone.sendConferenceCallBroadcast#c6701900 as nil")
	}
	b.PutID(PhoneSendConferenceCallBroadcastRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *PhoneSendConferenceCallBroadcastRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode phone.sendConferenceCallBroadcast#c6701900 as nil")
	}
	if s.Call == nil {
		return fmt.Errorf("unable to encode phone.sendConferenceCallBroadcast#c6701900: field call is nil")
	}
	if err := s.Call.Encode(b); err != nil {
		return fmt.Errorf("unable to encode phone.sendConferenceCallBroadcast#c6701900: field call: %w", err)
	}
	b.PutBytes(s.Block)
	return nil
}

// Decode implements bin.Decoder.
func (s *PhoneSendConferenceCallBroadcastRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode phone.sendConferenceCallBroadcast#c6701900 to nil")
	}
	if err := b.ConsumeID(PhoneSendConferenceCallBroadcastRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode phone.sendConferenceCallBroadcast#c6701900: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *PhoneSendConferenceCallBroadcastRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode phone.sendConferenceCallBroadcast#c6701900 to nil")
	}
	{
		value, err := DecodeInputGroupCall(b)
		if err != nil {
			return fmt.Errorf("unable to decode phone.sendConferenceCallBroadcast#c6701900: field call: %w", err)
		}
		s.Call = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode phone.sendConferenceCallBroadcast#c6701900: field block: %w", err)
		}
		s.Block = value
	}
	return nil
}

// GetCall returns value of Call field.
func (s *PhoneSendConferenceCallBroadcastRequest) GetCall() (value InputGroupCallClass) {
	if s == nil {
		return
	}
	return s.Call
}

// GetBlock returns value of Block field.
func (s *PhoneSendConferenceCallBroadcastRequest) GetBlock() (value []byte) {
	if s == nil {
		return
	}
	return s.Block
}

// PhoneSendConferenceCallBroadcast invokes method phone.sendConferenceCallBroadcast#c6701900 returning error if any.
// Broadcast a blockchain block to all members of a conference call, see here »¹ for
// more info.
//
// Links:
//  1. https://core.telegram.org/api/end-to-end/group-calls
//
// Possible errors:
//
//	400 GROUPCALL_INVALID: The specified group call is invalid.
//
// See https://core.telegram.org/method/phone.sendConferenceCallBroadcast for reference.
func (c *Client) PhoneSendConferenceCallBroadcast(ctx context.Context, request *PhoneSendConferenceCallBroadcastRequest) (UpdatesClass, error) {
	var result UpdatesBox

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