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

// PhoneDeleteGroupCallParticipantMessagesRequest represents TL type `phone.deleteGroupCallParticipantMessages#1dbfeca0`.
//
// See https://core.telegram.org/method/phone.deleteGroupCallParticipantMessages for reference.
type PhoneDeleteGroupCallParticipantMessagesRequest struct {
	// Flags field of PhoneDeleteGroupCallParticipantMessagesRequest.
	Flags bin.Fields
	// ReportSpam field of PhoneDeleteGroupCallParticipantMessagesRequest.
	ReportSpam bool
	// Call field of PhoneDeleteGroupCallParticipantMessagesRequest.
	Call InputGroupCallClass
	// Participant field of PhoneDeleteGroupCallParticipantMessagesRequest.
	Participant InputPeerClass
}

// PhoneDeleteGroupCallParticipantMessagesRequestTypeID is TL type id of PhoneDeleteGroupCallParticipantMessagesRequest.
const PhoneDeleteGroupCallParticipantMessagesRequestTypeID = 0x1dbfeca0

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

func (d *PhoneDeleteGroupCallParticipantMessagesRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.Flags.Zero()) {
		return false
	}
	if !(d.ReportSpam == false) {
		return false
	}
	if !(d.Call == nil) {
		return false
	}
	if !(d.Participant == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneDeleteGroupCallParticipantMessagesRequest from given interface.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) FillFrom(from interface {
	GetReportSpam() (value bool)
	GetCall() (value InputGroupCallClass)
	GetParticipant() (value InputPeerClass)
}) {
	d.ReportSpam = from.GetReportSpam()
	d.Call = from.GetCall()
	d.Participant = from.GetParticipant()
}

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

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

// TypeInfo returns info about TL type.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.deleteGroupCallParticipantMessages",
		ID:   PhoneDeleteGroupCallParticipantMessagesRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ReportSpam",
			SchemaName: "report_spam",
			Null:       !d.Flags.Has(0),
		},
		{
			Name:       "Call",
			SchemaName: "call",
		},
		{
			Name:       "Participant",
			SchemaName: "participant",
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) SetFlags() {
	if !(d.ReportSpam == false) {
		d.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode phone.deleteGroupCallParticipantMessages#1dbfeca0 as nil")
	}
	b.PutID(PhoneDeleteGroupCallParticipantMessagesRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode phone.deleteGroupCallParticipantMessages#1dbfeca0 as nil")
	}
	d.SetFlags()
	if err := d.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode phone.deleteGroupCallParticipantMessages#1dbfeca0: field flags: %w", err)
	}
	if d.Call == nil {
		return fmt.Errorf("unable to encode phone.deleteGroupCallParticipantMessages#1dbfeca0: field call is nil")
	}
	if err := d.Call.Encode(b); err != nil {
		return fmt.Errorf("unable to encode phone.deleteGroupCallParticipantMessages#1dbfeca0: field call: %w", err)
	}
	if d.Participant == nil {
		return fmt.Errorf("unable to encode phone.deleteGroupCallParticipantMessages#1dbfeca0: field participant is nil")
	}
	if err := d.Participant.Encode(b); err != nil {
		return fmt.Errorf("unable to encode phone.deleteGroupCallParticipantMessages#1dbfeca0: field participant: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode phone.deleteGroupCallParticipantMessages#1dbfeca0 to nil")
	}
	if err := b.ConsumeID(PhoneDeleteGroupCallParticipantMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode phone.deleteGroupCallParticipantMessages#1dbfeca0: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode phone.deleteGroupCallParticipantMessages#1dbfeca0 to nil")
	}
	{
		if err := d.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode phone.deleteGroupCallParticipantMessages#1dbfeca0: field flags: %w", err)
		}
	}
	d.ReportSpam = d.Flags.Has(0)
	{
		value, err := DecodeInputGroupCall(b)
		if err != nil {
			return fmt.Errorf("unable to decode phone.deleteGroupCallParticipantMessages#1dbfeca0: field call: %w", err)
		}
		d.Call = value
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode phone.deleteGroupCallParticipantMessages#1dbfeca0: field participant: %w", err)
		}
		d.Participant = value
	}
	return nil
}

// SetReportSpam sets value of ReportSpam conditional field.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) SetReportSpam(value bool) {
	if value {
		d.Flags.Set(0)
		d.ReportSpam = true
	} else {
		d.Flags.Unset(0)
		d.ReportSpam = false
	}
}

// GetReportSpam returns value of ReportSpam conditional field.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) GetReportSpam() (value bool) {
	if d == nil {
		return
	}
	return d.Flags.Has(0)
}

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

// GetParticipant returns value of Participant field.
func (d *PhoneDeleteGroupCallParticipantMessagesRequest) GetParticipant() (value InputPeerClass) {
	if d == nil {
		return
	}
	return d.Participant
}

// PhoneDeleteGroupCallParticipantMessages invokes method phone.deleteGroupCallParticipantMessages#1dbfeca0 returning error if any.
//
// See https://core.telegram.org/method/phone.deleteGroupCallParticipantMessages for reference.
func (c *Client) PhoneDeleteGroupCallParticipantMessages(ctx context.Context, request *PhoneDeleteGroupCallParticipantMessagesRequest) (UpdatesClass, error) {
	var result UpdatesBox

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