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

// SetMessageSenderBotVerificationRequest represents TL type `setMessageSenderBotVerification#b4c1da4a`.
type SetMessageSenderBotVerificationRequest struct {
	// Identifier of the owned bot, which will verify the user or the chat
	BotUserID int64
	// Identifier of the user or the supergroup or channel chat, which will be verified by
	// the bot
	VerifiedID MessageSenderClass
	// Custom description of verification reason;
	// 0-getOption("bot_verification_custom_description_length_max").
	CustomDescription string
}

// SetMessageSenderBotVerificationRequestTypeID is TL type id of SetMessageSenderBotVerificationRequest.
const SetMessageSenderBotVerificationRequestTypeID = 0xb4c1da4a

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

func (s *SetMessageSenderBotVerificationRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.BotUserID == 0) {
		return false
	}
	if !(s.VerifiedID == nil) {
		return false
	}
	if !(s.CustomDescription == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetMessageSenderBotVerificationRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setMessageSenderBotVerification",
		ID:   SetMessageSenderBotVerificationRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "VerifiedID",
			SchemaName: "verified_id",
		},
		{
			Name:       "CustomDescription",
			SchemaName: "custom_description",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetMessageSenderBotVerificationRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setMessageSenderBotVerification#b4c1da4a as nil")
	}
	b.PutID(SetMessageSenderBotVerificationRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetMessageSenderBotVerificationRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setMessageSenderBotVerification#b4c1da4a as nil")
	}
	b.PutInt53(s.BotUserID)
	if s.VerifiedID == nil {
		return fmt.Errorf("unable to encode setMessageSenderBotVerification#b4c1da4a: field verified_id is nil")
	}
	if err := s.VerifiedID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setMessageSenderBotVerification#b4c1da4a: field verified_id: %w", err)
	}
	b.PutString(s.CustomDescription)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetMessageSenderBotVerificationRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setMessageSenderBotVerification#b4c1da4a to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: field bot_user_id: %w", err)
		}
		s.BotUserID = value
	}
	{
		value, err := DecodeMessageSender(b)
		if err != nil {
			return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: field verified_id: %w", err)
		}
		s.VerifiedID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: field custom_description: %w", err)
		}
		s.CustomDescription = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetMessageSenderBotVerificationRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setMessageSenderBotVerification#b4c1da4a as nil")
	}
	b.ObjStart()
	b.PutID("setMessageSenderBotVerification")
	b.Comma()
	b.FieldStart("bot_user_id")
	b.PutInt53(s.BotUserID)
	b.Comma()
	b.FieldStart("verified_id")
	if s.VerifiedID == nil {
		return fmt.Errorf("unable to encode setMessageSenderBotVerification#b4c1da4a: field verified_id is nil")
	}
	if err := s.VerifiedID.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setMessageSenderBotVerification#b4c1da4a: field verified_id: %w", err)
	}
	b.Comma()
	b.FieldStart("custom_description")
	b.PutString(s.CustomDescription)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setMessageSenderBotVerification"); err != nil {
				return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: %w", err)
			}
		case "bot_user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: field bot_user_id: %w", err)
			}
			s.BotUserID = value
		case "verified_id":
			value, err := DecodeTDLibJSONMessageSender(b)
			if err != nil {
				return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: field verified_id: %w", err)
			}
			s.VerifiedID = value
		case "custom_description":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setMessageSenderBotVerification#b4c1da4a: field custom_description: %w", err)
			}
			s.CustomDescription = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBotUserID returns value of BotUserID field.
func (s *SetMessageSenderBotVerificationRequest) GetBotUserID() (value int64) {
	if s == nil {
		return
	}
	return s.BotUserID
}

// GetVerifiedID returns value of VerifiedID field.
func (s *SetMessageSenderBotVerificationRequest) GetVerifiedID() (value MessageSenderClass) {
	if s == nil {
		return
	}
	return s.VerifiedID
}

// GetCustomDescription returns value of CustomDescription field.
func (s *SetMessageSenderBotVerificationRequest) GetCustomDescription() (value string) {
	if s == nil {
		return
	}
	return s.CustomDescription
}

// SetMessageSenderBotVerification invokes method setMessageSenderBotVerification#b4c1da4a returning error if any.
func (c *Client) SetMessageSenderBotVerification(ctx context.Context, request *SetMessageSenderBotVerificationRequest) error {
	var ok Ok

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