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

// ReadBusinessMessageRequest represents TL type `readBusinessMessage#9944feee`.
type ReadBusinessMessageRequest struct {
	// Unique identifier of business connection through which the message was received
	BusinessConnectionID string
	// The chat the message belongs to
	ChatID int64
	// Identifier of the message
	MessageID int64
}

// ReadBusinessMessageRequestTypeID is TL type id of ReadBusinessMessageRequest.
const ReadBusinessMessageRequestTypeID = 0x9944feee

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

func (r *ReadBusinessMessageRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.BusinessConnectionID == "") {
		return false
	}
	if !(r.ChatID == 0) {
		return false
	}
	if !(r.MessageID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReadBusinessMessageRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "readBusinessMessage",
		ID:   ReadBusinessMessageRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BusinessConnectionID",
			SchemaName: "business_connection_id",
		},
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReadBusinessMessageRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode readBusinessMessage#9944feee as nil")
	}
	b.PutID(ReadBusinessMessageRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReadBusinessMessageRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode readBusinessMessage#9944feee as nil")
	}
	b.PutString(r.BusinessConnectionID)
	b.PutInt53(r.ChatID)
	b.PutInt53(r.MessageID)
	return nil
}

// Decode implements bin.Decoder.
func (r *ReadBusinessMessageRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode readBusinessMessage#9944feee to nil")
	}
	if err := b.ConsumeID(ReadBusinessMessageRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode readBusinessMessage#9944feee: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ReadBusinessMessageRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode readBusinessMessage#9944feee to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode readBusinessMessage#9944feee: field business_connection_id: %w", err)
		}
		r.BusinessConnectionID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode readBusinessMessage#9944feee: field chat_id: %w", err)
		}
		r.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode readBusinessMessage#9944feee: field message_id: %w", err)
		}
		r.MessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReadBusinessMessageRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode readBusinessMessage#9944feee as nil")
	}
	b.ObjStart()
	b.PutID("readBusinessMessage")
	b.Comma()
	b.FieldStart("business_connection_id")
	b.PutString(r.BusinessConnectionID)
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(r.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(r.MessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ReadBusinessMessageRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode readBusinessMessage#9944feee to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("readBusinessMessage"); err != nil {
				return fmt.Errorf("unable to decode readBusinessMessage#9944feee: %w", err)
			}
		case "business_connection_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode readBusinessMessage#9944feee: field business_connection_id: %w", err)
			}
			r.BusinessConnectionID = value
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode readBusinessMessage#9944feee: field chat_id: %w", err)
			}
			r.ChatID = value
		case "message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode readBusinessMessage#9944feee: field message_id: %w", err)
			}
			r.MessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBusinessConnectionID returns value of BusinessConnectionID field.
func (r *ReadBusinessMessageRequest) GetBusinessConnectionID() (value string) {
	if r == nil {
		return
	}
	return r.BusinessConnectionID
}

// GetChatID returns value of ChatID field.
func (r *ReadBusinessMessageRequest) GetChatID() (value int64) {
	if r == nil {
		return
	}
	return r.ChatID
}

// GetMessageID returns value of MessageID field.
func (r *ReadBusinessMessageRequest) GetMessageID() (value int64) {
	if r == nil {
		return
	}
	return r.MessageID
}

// ReadBusinessMessage invokes method readBusinessMessage#9944feee returning error if any.
func (c *Client) ReadBusinessMessage(ctx context.Context, request *ReadBusinessMessageRequest) error {
	var ok Ok

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