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

// InviteGroupCallParticipantRequest represents TL type `inviteGroupCallParticipant#da5b88ca`.
type InviteGroupCallParticipantRequest struct {
	// Group call identifier
	GroupCallID int32
	// User identifier
	UserID int64
	// Pass true if the group call is a video call
	IsVideo bool
}

// InviteGroupCallParticipantRequestTypeID is TL type id of InviteGroupCallParticipantRequest.
const InviteGroupCallParticipantRequestTypeID = 0xda5b88ca

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

func (i *InviteGroupCallParticipantRequest) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.GroupCallID == 0) {
		return false
	}
	if !(i.UserID == 0) {
		return false
	}
	if !(i.IsVideo == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (i *InviteGroupCallParticipantRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inviteGroupCallParticipant",
		ID:   InviteGroupCallParticipantRequestTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "IsVideo",
			SchemaName: "is_video",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InviteGroupCallParticipantRequest) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteGroupCallParticipant#da5b88ca as nil")
	}
	b.PutID(InviteGroupCallParticipantRequestTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InviteGroupCallParticipantRequest) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteGroupCallParticipant#da5b88ca as nil")
	}
	b.PutInt32(i.GroupCallID)
	b.PutInt53(i.UserID)
	b.PutBool(i.IsVideo)
	return nil
}

// Decode implements bin.Decoder.
func (i *InviteGroupCallParticipantRequest) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteGroupCallParticipant#da5b88ca to nil")
	}
	if err := b.ConsumeID(InviteGroupCallParticipantRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InviteGroupCallParticipantRequest) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteGroupCallParticipant#da5b88ca to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: field group_call_id: %w", err)
		}
		i.GroupCallID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: field user_id: %w", err)
		}
		i.UserID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: field is_video: %w", err)
		}
		i.IsVideo = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (i *InviteGroupCallParticipantRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if i == nil {
		return fmt.Errorf("can't encode inviteGroupCallParticipant#da5b88ca as nil")
	}
	b.ObjStart()
	b.PutID("inviteGroupCallParticipant")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(i.GroupCallID)
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(i.UserID)
	b.Comma()
	b.FieldStart("is_video")
	b.PutBool(i.IsVideo)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (i *InviteGroupCallParticipantRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if i == nil {
		return fmt.Errorf("can't decode inviteGroupCallParticipant#da5b88ca to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("inviteGroupCallParticipant"); err != nil {
				return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: %w", err)
			}
		case "group_call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: field group_call_id: %w", err)
			}
			i.GroupCallID = value
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: field user_id: %w", err)
			}
			i.UserID = value
		case "is_video":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode inviteGroupCallParticipant#da5b88ca: field is_video: %w", err)
			}
			i.IsVideo = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetUserID returns value of UserID field.
func (i *InviteGroupCallParticipantRequest) GetUserID() (value int64) {
	if i == nil {
		return
	}
	return i.UserID
}

// GetIsVideo returns value of IsVideo field.
func (i *InviteGroupCallParticipantRequest) GetIsVideo() (value bool) {
	if i == nil {
		return
	}
	return i.IsVideo
}

// InviteGroupCallParticipant invokes method inviteGroupCallParticipant#da5b88ca returning error if any.
func (c *Client) InviteGroupCallParticipant(ctx context.Context, request *InviteGroupCallParticipantRequest) (InviteGroupCallParticipantResultClass, error) {
	var result InviteGroupCallParticipantResultBox

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