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

// PhoneGetGroupCallStarsRequest represents TL type `phone.getGroupCallStars#6f636302`.
//
// See https://core.telegram.org/method/phone.getGroupCallStars for reference.
type PhoneGetGroupCallStarsRequest struct {
	// Call field of PhoneGetGroupCallStarsRequest.
	Call InputGroupCallClass
}

// PhoneGetGroupCallStarsRequestTypeID is TL type id of PhoneGetGroupCallStarsRequest.
const PhoneGetGroupCallStarsRequestTypeID = 0x6f636302

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

func (g *PhoneGetGroupCallStarsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Call == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneGetGroupCallStarsRequest from given interface.
func (g *PhoneGetGroupCallStarsRequest) FillFrom(from interface {
	GetCall() (value InputGroupCallClass)
}) {
	g.Call = from.GetCall()
}

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

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

// TypeInfo returns info about TL type.
func (g *PhoneGetGroupCallStarsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.getGroupCallStars",
		ID:   PhoneGetGroupCallStarsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Call",
			SchemaName: "call",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PhoneGetGroupCallStarsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode phone.getGroupCallStars#6f636302 as nil")
	}
	b.PutID(PhoneGetGroupCallStarsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *PhoneGetGroupCallStarsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode phone.getGroupCallStars#6f636302 as nil")
	}
	if g.Call == nil {
		return fmt.Errorf("unable to encode phone.getGroupCallStars#6f636302: field call is nil")
	}
	if err := g.Call.Encode(b); err != nil {
		return fmt.Errorf("unable to encode phone.getGroupCallStars#6f636302: field call: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *PhoneGetGroupCallStarsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode phone.getGroupCallStars#6f636302 to nil")
	}
	{
		value, err := DecodeInputGroupCall(b)
		if err != nil {
			return fmt.Errorf("unable to decode phone.getGroupCallStars#6f636302: field call: %w", err)
		}
		g.Call = value
	}
	return nil
}

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

// PhoneGetGroupCallStars invokes method phone.getGroupCallStars#6f636302 returning error if any.
//
// See https://core.telegram.org/method/phone.getGroupCallStars for reference.
func (c *Client) PhoneGetGroupCallStars(ctx context.Context, call InputGroupCallClass) (*PhoneGroupCallStars, error) {
	var result PhoneGroupCallStars

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