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

// SetGroupCallParticipantVolumeLevelRequest represents TL type `setGroupCallParticipantVolumeLevel#97779828`.
type SetGroupCallParticipantVolumeLevelRequest struct {
	// Group call identifier
	GroupCallID int32
	// Participant identifier
	ParticipantID MessageSenderClass
	// New participant's volume level; 1-20000 in hundreds of percents
	VolumeLevel int32
}

// SetGroupCallParticipantVolumeLevelRequestTypeID is TL type id of SetGroupCallParticipantVolumeLevelRequest.
const SetGroupCallParticipantVolumeLevelRequestTypeID = 0x97779828

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

func (s *SetGroupCallParticipantVolumeLevelRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.GroupCallID == 0) {
		return false
	}
	if !(s.ParticipantID == nil) {
		return false
	}
	if !(s.VolumeLevel == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetGroupCallParticipantVolumeLevelRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setGroupCallParticipantVolumeLevel",
		ID:   SetGroupCallParticipantVolumeLevelRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "ParticipantID",
			SchemaName: "participant_id",
		},
		{
			Name:       "VolumeLevel",
			SchemaName: "volume_level",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetGroupCallParticipantVolumeLevelRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setGroupCallParticipantVolumeLevel#97779828 as nil")
	}
	b.PutID(SetGroupCallParticipantVolumeLevelRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetGroupCallParticipantVolumeLevelRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setGroupCallParticipantVolumeLevel#97779828 as nil")
	}
	b.PutInt32(s.GroupCallID)
	if s.ParticipantID == nil {
		return fmt.Errorf("unable to encode setGroupCallParticipantVolumeLevel#97779828: field participant_id is nil")
	}
	if err := s.ParticipantID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setGroupCallParticipantVolumeLevel#97779828: field participant_id: %w", err)
	}
	b.PutInt32(s.VolumeLevel)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetGroupCallParticipantVolumeLevelRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setGroupCallParticipantVolumeLevel#97779828 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: field group_call_id: %w", err)
		}
		s.GroupCallID = value
	}
	{
		value, err := DecodeMessageSender(b)
		if err != nil {
			return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: field participant_id: %w", err)
		}
		s.ParticipantID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: field volume_level: %w", err)
		}
		s.VolumeLevel = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetGroupCallParticipantVolumeLevelRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setGroupCallParticipantVolumeLevel#97779828 as nil")
	}
	b.ObjStart()
	b.PutID("setGroupCallParticipantVolumeLevel")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(s.GroupCallID)
	b.Comma()
	b.FieldStart("participant_id")
	if s.ParticipantID == nil {
		return fmt.Errorf("unable to encode setGroupCallParticipantVolumeLevel#97779828: field participant_id is nil")
	}
	if err := s.ParticipantID.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setGroupCallParticipantVolumeLevel#97779828: field participant_id: %w", err)
	}
	b.Comma()
	b.FieldStart("volume_level")
	b.PutInt32(s.VolumeLevel)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setGroupCallParticipantVolumeLevel"); err != nil {
				return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: %w", err)
			}
		case "group_call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: field group_call_id: %w", err)
			}
			s.GroupCallID = value
		case "participant_id":
			value, err := DecodeTDLibJSONMessageSender(b)
			if err != nil {
				return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: field participant_id: %w", err)
			}
			s.ParticipantID = value
		case "volume_level":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode setGroupCallParticipantVolumeLevel#97779828: field volume_level: %w", err)
			}
			s.VolumeLevel = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetParticipantID returns value of ParticipantID field.
func (s *SetGroupCallParticipantVolumeLevelRequest) GetParticipantID() (value MessageSenderClass) {
	if s == nil {
		return
	}
	return s.ParticipantID
}

// GetVolumeLevel returns value of VolumeLevel field.
func (s *SetGroupCallParticipantVolumeLevelRequest) GetVolumeLevel() (value int32) {
	if s == nil {
		return
	}
	return s.VolumeLevel
}

// SetGroupCallParticipantVolumeLevel invokes method setGroupCallParticipantVolumeLevel#97779828 returning error if any.
func (c *Client) SetGroupCallParticipantVolumeLevel(ctx context.Context, request *SetGroupCallParticipantVolumeLevelRequest) error {
	var ok Ok

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