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

// ToggleGroupCallIsMyVideoPausedRequest represents TL type `toggleGroupCallIsMyVideoPaused#e374f199`.
type ToggleGroupCallIsMyVideoPausedRequest struct {
	// Group call identifier
	GroupCallID int32
	// Pass true if the current user's video is paused
	IsMyVideoPaused bool
}

// ToggleGroupCallIsMyVideoPausedRequestTypeID is TL type id of ToggleGroupCallIsMyVideoPausedRequest.
const ToggleGroupCallIsMyVideoPausedRequestTypeID = 0xe374f199

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

func (t *ToggleGroupCallIsMyVideoPausedRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.GroupCallID == 0) {
		return false
	}
	if !(t.IsMyVideoPaused == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleGroupCallIsMyVideoPausedRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleGroupCallIsMyVideoPaused",
		ID:   ToggleGroupCallIsMyVideoPausedRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "IsMyVideoPaused",
			SchemaName: "is_my_video_paused",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleGroupCallIsMyVideoPausedRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGroupCallIsMyVideoPaused#e374f199 as nil")
	}
	b.PutID(ToggleGroupCallIsMyVideoPausedRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleGroupCallIsMyVideoPausedRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGroupCallIsMyVideoPaused#e374f199 as nil")
	}
	b.PutInt32(t.GroupCallID)
	b.PutBool(t.IsMyVideoPaused)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *ToggleGroupCallIsMyVideoPausedRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleGroupCallIsMyVideoPaused#e374f199 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode toggleGroupCallIsMyVideoPaused#e374f199: field group_call_id: %w", err)
		}
		t.GroupCallID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleGroupCallIsMyVideoPaused#e374f199: field is_my_video_paused: %w", err)
		}
		t.IsMyVideoPaused = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleGroupCallIsMyVideoPausedRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGroupCallIsMyVideoPaused#e374f199 as nil")
	}
	b.ObjStart()
	b.PutID("toggleGroupCallIsMyVideoPaused")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(t.GroupCallID)
	b.Comma()
	b.FieldStart("is_my_video_paused")
	b.PutBool(t.IsMyVideoPaused)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

// GetIsMyVideoPaused returns value of IsMyVideoPaused field.
func (t *ToggleGroupCallIsMyVideoPausedRequest) GetIsMyVideoPaused() (value bool) {
	if t == nil {
		return
	}
	return t.IsMyVideoPaused
}

// ToggleGroupCallIsMyVideoPaused invokes method toggleGroupCallIsMyVideoPaused#e374f199 returning error if any.
func (c *Client) ToggleGroupCallIsMyVideoPaused(ctx context.Context, request *ToggleGroupCallIsMyVideoPausedRequest) error {
	var ok Ok

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