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

// PhoneEditGroupCallTitleRequest represents TL type `phone.editGroupCallTitle#1ca6ac0a`.
// Edit the title of a group call or livestream
//
// See https://core.telegram.org/method/phone.editGroupCallTitle for reference.
type PhoneEditGroupCallTitleRequest struct {
	// Group call
	Call InputGroupCallClass
	// New title
	Title string
}

// PhoneEditGroupCallTitleRequestTypeID is TL type id of PhoneEditGroupCallTitleRequest.
const PhoneEditGroupCallTitleRequestTypeID = 0x1ca6ac0a

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

func (e *PhoneEditGroupCallTitleRequest) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Call == nil) {
		return false
	}
	if !(e.Title == "") {
		return false
	}

	return true
}

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

// FillFrom fills PhoneEditGroupCallTitleRequest from given interface.
func (e *PhoneEditGroupCallTitleRequest) FillFrom(from interface {
	GetCall() (value InputGroupCallClass)
	GetTitle() (value string)
}) {
	e.Call = from.GetCall()
	e.Title = from.GetTitle()
}

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

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

// TypeInfo returns info about TL type.
func (e *PhoneEditGroupCallTitleRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.editGroupCallTitle",
		ID:   PhoneEditGroupCallTitleRequestTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Call",
			SchemaName: "call",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *PhoneEditGroupCallTitleRequest) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode phone.editGroupCallTitle#1ca6ac0a as nil")
	}
	b.PutID(PhoneEditGroupCallTitleRequestTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *PhoneEditGroupCallTitleRequest) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode phone.editGroupCallTitle#1ca6ac0a as nil")
	}
	if e.Call == nil {
		return fmt.Errorf("unable to encode phone.editGroupCallTitle#1ca6ac0a: field call is nil")
	}
	if err := e.Call.Encode(b); err != nil {
		return fmt.Errorf("unable to encode phone.editGroupCallTitle#1ca6ac0a: field call: %w", err)
	}
	b.PutString(e.Title)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (e *PhoneEditGroupCallTitleRequest) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode phone.editGroupCallTitle#1ca6ac0a to nil")
	}
	{
		value, err := DecodeInputGroupCall(b)
		if err != nil {
			return fmt.Errorf("unable to decode phone.editGroupCallTitle#1ca6ac0a: field call: %w", err)
		}
		e.Call = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode phone.editGroupCallTitle#1ca6ac0a: field title: %w", err)
		}
		e.Title = value
	}
	return nil
}

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

// GetTitle returns value of Title field.
func (e *PhoneEditGroupCallTitleRequest) GetTitle() (value string) {
	if e == nil {
		return
	}
	return e.Title
}

// PhoneEditGroupCallTitle invokes method phone.editGroupCallTitle#1ca6ac0a returning error if any.
// Edit the title of a group call or livestream
//
// Possible errors:
//
//	403 GROUPCALL_FORBIDDEN: The group call has already ended.
//	400 GROUPCALL_INVALID: The specified group call is invalid.
//
// See https://core.telegram.org/method/phone.editGroupCallTitle for reference.
func (c *Client) PhoneEditGroupCallTitle(ctx context.Context, request *PhoneEditGroupCallTitleRequest) (UpdatesClass, error) {
	var result UpdatesBox

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