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

// SetUserSupportInfoRequest represents TL type `setUserSupportInfo#837c9803`.
type SetUserSupportInfoRequest struct {
	// User identifier
	UserID int64
	// New information message
	Message FormattedText
}

// SetUserSupportInfoRequestTypeID is TL type id of SetUserSupportInfoRequest.
const SetUserSupportInfoRequestTypeID = 0x837c9803

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

func (s *SetUserSupportInfoRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.UserID == 0) {
		return false
	}
	if !(s.Message.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetUserSupportInfoRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setUserSupportInfo",
		ID:   SetUserSupportInfoRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetUserSupportInfoRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setUserSupportInfo#837c9803 as nil")
	}
	b.PutID(SetUserSupportInfoRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetUserSupportInfoRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setUserSupportInfo#837c9803 as nil")
	}
	b.PutInt53(s.UserID)
	if err := s.Message.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setUserSupportInfo#837c9803: field message: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetUserSupportInfoRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setUserSupportInfo#837c9803 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setUserSupportInfo#837c9803: field user_id: %w", err)
		}
		s.UserID = value
	}
	{
		if err := s.Message.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setUserSupportInfo#837c9803: field message: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetUserSupportInfoRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setUserSupportInfo#837c9803 as nil")
	}
	b.ObjStart()
	b.PutID("setUserSupportInfo")
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(s.UserID)
	b.Comma()
	b.FieldStart("message")
	if err := s.Message.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setUserSupportInfo#837c9803: field message: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setUserSupportInfo"); err != nil {
				return fmt.Errorf("unable to decode setUserSupportInfo#837c9803: %w", err)
			}
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setUserSupportInfo#837c9803: field user_id: %w", err)
			}
			s.UserID = value
		case "message":
			if err := s.Message.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode setUserSupportInfo#837c9803: field message: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetMessage returns value of Message field.
func (s *SetUserSupportInfoRequest) GetMessage() (value FormattedText) {
	if s == nil {
		return
	}
	return s.Message
}

// SetUserSupportInfo invokes method setUserSupportInfo#837c9803 returning error if any.
func (c *Client) SetUserSupportInfo(ctx context.Context, request *SetUserSupportInfoRequest) (*UserSupportInfo, error) {
	var result UserSupportInfo

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