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

// RateSpeechRecognitionRequest represents TL type `rateSpeechRecognition#eedcc3b5`.
type RateSpeechRecognitionRequest struct {
	// Identifier of the chat to which the message belongs
	ChatID int64
	// Identifier of the message
	MessageID int64
	// Pass true if the speech recognition is good
	IsGood bool
}

// RateSpeechRecognitionRequestTypeID is TL type id of RateSpeechRecognitionRequest.
const RateSpeechRecognitionRequestTypeID = 0xeedcc3b5

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *RateSpeechRecognitionRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "rateSpeechRecognition",
		ID:   RateSpeechRecognitionRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
		{
			Name:       "IsGood",
			SchemaName: "is_good",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *RateSpeechRecognitionRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode rateSpeechRecognition#eedcc3b5 as nil")
	}
	b.PutID(RateSpeechRecognitionRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *RateSpeechRecognitionRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode rateSpeechRecognition#eedcc3b5 as nil")
	}
	b.PutInt53(r.ChatID)
	b.PutInt53(r.MessageID)
	b.PutBool(r.IsGood)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (r *RateSpeechRecognitionRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode rateSpeechRecognition#eedcc3b5 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode rateSpeechRecognition#eedcc3b5: field chat_id: %w", err)
		}
		r.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode rateSpeechRecognition#eedcc3b5: field message_id: %w", err)
		}
		r.MessageID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode rateSpeechRecognition#eedcc3b5: field is_good: %w", err)
		}
		r.IsGood = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *RateSpeechRecognitionRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode rateSpeechRecognition#eedcc3b5 as nil")
	}
	b.ObjStart()
	b.PutID("rateSpeechRecognition")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(r.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(r.MessageID)
	b.Comma()
	b.FieldStart("is_good")
	b.PutBool(r.IsGood)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

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

// GetIsGood returns value of IsGood field.
func (r *RateSpeechRecognitionRequest) GetIsGood() (value bool) {
	if r == nil {
		return
	}
	return r.IsGood
}

// RateSpeechRecognition invokes method rateSpeechRecognition#eedcc3b5 returning error if any.
func (c *Client) RateSpeechRecognition(ctx context.Context, request *RateSpeechRecognitionRequest) error {
	var ok Ok

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