// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// RevokeGroupCallInviteLinkRequest represents TL type `revokeGroupCallInviteLink#1de5a494`.
type RevokeGroupCallInviteLinkRequest struct {
	// Group call identifier
	GroupCallID int32
}

// RevokeGroupCallInviteLinkRequestTypeID is TL type id of RevokeGroupCallInviteLinkRequest.
const RevokeGroupCallInviteLinkRequestTypeID = 0x1de5a494

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

func (r *RevokeGroupCallInviteLinkRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.GroupCallID == 0) {
		return false
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*RevokeGroupCallInviteLinkRequest) TypeName() string {
	return "revokeGroupCallInviteLink"
}

// TypeInfo returns info about TL type.
func (r *RevokeGroupCallInviteLinkRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "revokeGroupCallInviteLink",
		ID:   RevokeGroupCallInviteLinkRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *RevokeGroupCallInviteLinkRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode revokeGroupCallInviteLink#1de5a494 as nil")
	}
	b.PutID(RevokeGroupCallInviteLinkRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *RevokeGroupCallInviteLinkRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode revokeGroupCallInviteLink#1de5a494 as nil")
	}
	b.PutInt32(r.GroupCallID)
	return nil
}

// Decode implements bin.Decoder.
func (r *RevokeGroupCallInviteLinkRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode revokeGroupCallInviteLink#1de5a494 to nil")
	}
	if err := b.ConsumeID(RevokeGroupCallInviteLinkRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode revokeGroupCallInviteLink#1de5a494: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *RevokeGroupCallInviteLinkRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode revokeGroupCallInviteLink#1de5a494 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode revokeGroupCallInviteLink#1de5a494: field group_call_id: %w", err)
		}
		r.GroupCallID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *RevokeGroupCallInviteLinkRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode revokeGroupCallInviteLink#1de5a494 as nil")
	}
	b.ObjStart()
	b.PutID("revokeGroupCallInviteLink")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(r.GroupCallID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *RevokeGroupCallInviteLinkRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode revokeGroupCallInviteLink#1de5a494 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("revokeGroupCallInviteLink"); err != nil {
				return fmt.Errorf("unable to decode revokeGroupCallInviteLink#1de5a494: %w", err)
			}
		case "group_call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode revokeGroupCallInviteLink#1de5a494: field group_call_id: %w", err)
			}
			r.GroupCallID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetGroupCallID returns value of GroupCallID field.
func (r *RevokeGroupCallInviteLinkRequest) GetGroupCallID() (value int32) {
	if r == nil {
		return
	}
	return r.GroupCallID
}

// RevokeGroupCallInviteLink invokes method revokeGroupCallInviteLink#1de5a494 returning error if any.
func (c *Client) RevokeGroupCallInviteLink(ctx context.Context, groupcallid int32) error {
	var ok Ok

	request := &RevokeGroupCallInviteLinkRequest{
		GroupCallID: groupcallid,
	}
	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
