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

// PhoneSendGroupCallEncryptedMessageRequest represents TL type `phone.sendGroupCallEncryptedMessage#e5afa56d`.
//
// See https://core.telegram.org/method/phone.sendGroupCallEncryptedMessage for reference.
type PhoneSendGroupCallEncryptedMessageRequest struct {
	// Call field of PhoneSendGroupCallEncryptedMessageRequest.
	Call InputGroupCallClass
	// EncryptedMessage field of PhoneSendGroupCallEncryptedMessageRequest.
	EncryptedMessage []byte
}

// PhoneSendGroupCallEncryptedMessageRequestTypeID is TL type id of PhoneSendGroupCallEncryptedMessageRequest.
const PhoneSendGroupCallEncryptedMessageRequestTypeID = 0xe5afa56d

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

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

	return true
}

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

// FillFrom fills PhoneSendGroupCallEncryptedMessageRequest from given interface.
func (s *PhoneSendGroupCallEncryptedMessageRequest) FillFrom(from interface {
	GetCall() (value InputGroupCallClass)
	GetEncryptedMessage() (value []byte)
}) {
	s.Call = from.GetCall()
	s.EncryptedMessage = from.GetEncryptedMessage()
}

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

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

// TypeInfo returns info about TL type.
func (s *PhoneSendGroupCallEncryptedMessageRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.sendGroupCallEncryptedMessage",
		ID:   PhoneSendGroupCallEncryptedMessageRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Call",
			SchemaName: "call",
		},
		{
			Name:       "EncryptedMessage",
			SchemaName: "encrypted_message",
		},
	}
	return typ
}

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

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

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

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

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

// GetEncryptedMessage returns value of EncryptedMessage field.
func (s *PhoneSendGroupCallEncryptedMessageRequest) GetEncryptedMessage() (value []byte) {
	if s == nil {
		return
	}
	return s.EncryptedMessage
}

// PhoneSendGroupCallEncryptedMessage invokes method phone.sendGroupCallEncryptedMessage#e5afa56d returning error if any.
//
// See https://core.telegram.org/method/phone.sendGroupCallEncryptedMessage for reference.
func (c *Client) PhoneSendGroupCallEncryptedMessage(ctx context.Context, request *PhoneSendGroupCallEncryptedMessageRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
