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

// SetLogTagVerbosityLevelRequest represents TL type `setLogTagVerbosityLevel#8317d696`.
type SetLogTagVerbosityLevelRequest struct {
	// Logging tag to change verbosity level
	Tag string
	// New verbosity level; 1-1024
	NewVerbosityLevel int32
}

// SetLogTagVerbosityLevelRequestTypeID is TL type id of SetLogTagVerbosityLevelRequest.
const SetLogTagVerbosityLevelRequestTypeID = 0x8317d696

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

func (s *SetLogTagVerbosityLevelRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Tag == "") {
		return false
	}
	if !(s.NewVerbosityLevel == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetLogTagVerbosityLevelRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setLogTagVerbosityLevel",
		ID:   SetLogTagVerbosityLevelRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Tag",
			SchemaName: "tag",
		},
		{
			Name:       "NewVerbosityLevel",
			SchemaName: "new_verbosity_level",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetLogTagVerbosityLevelRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setLogTagVerbosityLevel#8317d696 as nil")
	}
	b.PutID(SetLogTagVerbosityLevelRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetLogTagVerbosityLevelRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setLogTagVerbosityLevel#8317d696 as nil")
	}
	b.PutString(s.Tag)
	b.PutInt32(s.NewVerbosityLevel)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetLogTagVerbosityLevelRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setLogTagVerbosityLevel#8317d696 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setLogTagVerbosityLevel#8317d696: field tag: %w", err)
		}
		s.Tag = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode setLogTagVerbosityLevel#8317d696: field new_verbosity_level: %w", err)
		}
		s.NewVerbosityLevel = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetLogTagVerbosityLevelRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setLogTagVerbosityLevel#8317d696 as nil")
	}
	b.ObjStart()
	b.PutID("setLogTagVerbosityLevel")
	b.Comma()
	b.FieldStart("tag")
	b.PutString(s.Tag)
	b.Comma()
	b.FieldStart("new_verbosity_level")
	b.PutInt32(s.NewVerbosityLevel)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setLogTagVerbosityLevel"); err != nil {
				return fmt.Errorf("unable to decode setLogTagVerbosityLevel#8317d696: %w", err)
			}
		case "tag":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setLogTagVerbosityLevel#8317d696: field tag: %w", err)
			}
			s.Tag = value
		case "new_verbosity_level":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode setLogTagVerbosityLevel#8317d696: field new_verbosity_level: %w", err)
			}
			s.NewVerbosityLevel = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTag returns value of Tag field.
func (s *SetLogTagVerbosityLevelRequest) GetTag() (value string) {
	if s == nil {
		return
	}
	return s.Tag
}

// GetNewVerbosityLevel returns value of NewVerbosityLevel field.
func (s *SetLogTagVerbosityLevelRequest) GetNewVerbosityLevel() (value int32) {
	if s == nil {
		return
	}
	return s.NewVerbosityLevel
}

// SetLogTagVerbosityLevel invokes method setLogTagVerbosityLevel#8317d696 returning error if any.
func (c *Client) SetLogTagVerbosityLevel(ctx context.Context, request *SetLogTagVerbosityLevelRequest) error {
	var ok Ok

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