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

// RemoveMessageSenderBotVerificationRequest represents TL type `removeMessageSenderBotVerification#9a10cf5a`.
type RemoveMessageSenderBotVerificationRequest struct {
	// Identifier of the owned bot, which verified the user or the chat
	BotUserID int64
	// Identifier of the user or the supergroup or channel chat, which verification is
	// removed
	VerifiedID MessageSenderClass
}

// RemoveMessageSenderBotVerificationRequestTypeID is TL type id of RemoveMessageSenderBotVerificationRequest.
const RemoveMessageSenderBotVerificationRequestTypeID = 0x9a10cf5a

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

func (r *RemoveMessageSenderBotVerificationRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.BotUserID == 0) {
		return false
	}
	if !(r.VerifiedID == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *RemoveMessageSenderBotVerificationRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "removeMessageSenderBotVerification",
		ID:   RemoveMessageSenderBotVerificationRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BotUserID",
			SchemaName: "bot_user_id",
		},
		{
			Name:       "VerifiedID",
			SchemaName: "verified_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *RemoveMessageSenderBotVerificationRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removeMessageSenderBotVerification#9a10cf5a as nil")
	}
	b.PutID(RemoveMessageSenderBotVerificationRequestTypeID)
	return r.EncodeBare(b)
}

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

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

// DecodeBare implements bin.BareDecoder.
func (r *RemoveMessageSenderBotVerificationRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removeMessageSenderBotVerification#9a10cf5a to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode removeMessageSenderBotVerification#9a10cf5a: field bot_user_id: %w", err)
		}
		r.BotUserID = value
	}
	{
		value, err := DecodeMessageSender(b)
		if err != nil {
			return fmt.Errorf("unable to decode removeMessageSenderBotVerification#9a10cf5a: field verified_id: %w", err)
		}
		r.VerifiedID = value
	}
	return nil
}

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

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

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

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

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

// RemoveMessageSenderBotVerification invokes method removeMessageSenderBotVerification#9a10cf5a returning error if any.
func (c *Client) RemoveMessageSenderBotVerification(ctx context.Context, request *RemoveMessageSenderBotVerificationRequest) error {
	var ok Ok

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