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

// ToggleGroupCallIsMyVideoEnabledRequest represents TL type `toggleGroupCallIsMyVideoEnabled#9f2f50fa`.
type ToggleGroupCallIsMyVideoEnabledRequest struct {
	// Group call identifier
	GroupCallID int32
	// Pass true if the current user's video is enabled
	IsMyVideoEnabled bool
}

// ToggleGroupCallIsMyVideoEnabledRequestTypeID is TL type id of ToggleGroupCallIsMyVideoEnabledRequest.
const ToggleGroupCallIsMyVideoEnabledRequestTypeID = 0x9f2f50fa

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleGroupCallIsMyVideoEnabledRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleGroupCallIsMyVideoEnabled",
		ID:   ToggleGroupCallIsMyVideoEnabledRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "IsMyVideoEnabled",
			SchemaName: "is_my_video_enabled",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleGroupCallIsMyVideoEnabledRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGroupCallIsMyVideoEnabled#9f2f50fa as nil")
	}
	b.PutID(ToggleGroupCallIsMyVideoEnabledRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleGroupCallIsMyVideoEnabledRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGroupCallIsMyVideoEnabled#9f2f50fa as nil")
	}
	b.PutInt32(t.GroupCallID)
	b.PutBool(t.IsMyVideoEnabled)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *ToggleGroupCallIsMyVideoEnabledRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleGroupCallIsMyVideoEnabled#9f2f50fa to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode toggleGroupCallIsMyVideoEnabled#9f2f50fa: field group_call_id: %w", err)
		}
		t.GroupCallID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleGroupCallIsMyVideoEnabled#9f2f50fa: field is_my_video_enabled: %w", err)
		}
		t.IsMyVideoEnabled = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleGroupCallIsMyVideoEnabledRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleGroupCallIsMyVideoEnabled#9f2f50fa as nil")
	}
	b.ObjStart()
	b.PutID("toggleGroupCallIsMyVideoEnabled")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(t.GroupCallID)
	b.Comma()
	b.FieldStart("is_my_video_enabled")
	b.PutBool(t.IsMyVideoEnabled)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

// GetIsMyVideoEnabled returns value of IsMyVideoEnabled field.
func (t *ToggleGroupCallIsMyVideoEnabledRequest) GetIsMyVideoEnabled() (value bool) {
	if t == nil {
		return
	}
	return t.IsMyVideoEnabled
}

// ToggleGroupCallIsMyVideoEnabled invokes method toggleGroupCallIsMyVideoEnabled#9f2f50fa returning error if any.
func (c *Client) ToggleGroupCallIsMyVideoEnabled(ctx context.Context, request *ToggleGroupCallIsMyVideoEnabledRequest) error {
	var ok Ok

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