// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// InputMessageReadMetric represents TL type `inputMessageReadMetric#402b4495`.
//
// See https://core.telegram.org/constructor/inputMessageReadMetric for reference.
type InputMessageReadMetric struct {
	// MsgID field of InputMessageReadMetric.
	MsgID int
	// ViewID field of InputMessageReadMetric.
	ViewID int64
	// TimeInViewMs field of InputMessageReadMetric.
	TimeInViewMs int
	// ActiveTimeInViewMs field of InputMessageReadMetric.
	ActiveTimeInViewMs int
	// HeightToViewportRatioPermille field of InputMessageReadMetric.
	HeightToViewportRatioPermille int
	// SeenRangeRatioPermille field of InputMessageReadMetric.
	SeenRangeRatioPermille int
}

// InputMessageReadMetricTypeID is TL type id of InputMessageReadMetric.
const InputMessageReadMetricTypeID = 0x402b4495

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

func (i *InputMessageReadMetric) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.MsgID == 0) {
		return false
	}
	if !(i.ViewID == 0) {
		return false
	}
	if !(i.TimeInViewMs == 0) {
		return false
	}
	if !(i.ActiveTimeInViewMs == 0) {
		return false
	}
	if !(i.HeightToViewportRatioPermille == 0) {
		return false
	}
	if !(i.SeenRangeRatioPermille == 0) {
		return false
	}

	return true
}

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

// FillFrom fills InputMessageReadMetric from given interface.
func (i *InputMessageReadMetric) FillFrom(from interface {
	GetMsgID() (value int)
	GetViewID() (value int64)
	GetTimeInViewMs() (value int)
	GetActiveTimeInViewMs() (value int)
	GetHeightToViewportRatioPermille() (value int)
	GetSeenRangeRatioPermille() (value int)
}) {
	i.MsgID = from.GetMsgID()
	i.ViewID = from.GetViewID()
	i.TimeInViewMs = from.GetTimeInViewMs()
	i.ActiveTimeInViewMs = from.GetActiveTimeInViewMs()
	i.HeightToViewportRatioPermille = from.GetHeightToViewportRatioPermille()
	i.SeenRangeRatioPermille = from.GetSeenRangeRatioPermille()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputMessageReadMetric) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputMessageReadMetric",
		ID:   InputMessageReadMetricTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
		},
		{
			Name:       "ViewID",
			SchemaName: "view_id",
		},
		{
			Name:       "TimeInViewMs",
			SchemaName: "time_in_view_ms",
		},
		{
			Name:       "ActiveTimeInViewMs",
			SchemaName: "active_time_in_view_ms",
		},
		{
			Name:       "HeightToViewportRatioPermille",
			SchemaName: "height_to_viewport_ratio_permille",
		},
		{
			Name:       "SeenRangeRatioPermille",
			SchemaName: "seen_range_ratio_permille",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputMessageReadMetric) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputMessageReadMetric#402b4495 as nil")
	}
	b.PutID(InputMessageReadMetricTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputMessageReadMetric) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputMessageReadMetric#402b4495 as nil")
	}
	b.PutInt(i.MsgID)
	b.PutLong(i.ViewID)
	b.PutInt(i.TimeInViewMs)
	b.PutInt(i.ActiveTimeInViewMs)
	b.PutInt(i.HeightToViewportRatioPermille)
	b.PutInt(i.SeenRangeRatioPermille)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputMessageReadMetric) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputMessageReadMetric#402b4495 to nil")
	}
	if err := b.ConsumeID(InputMessageReadMetricTypeID); err != nil {
		return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputMessageReadMetric) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputMessageReadMetric#402b4495 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: field msg_id: %w", err)
		}
		i.MsgID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: field view_id: %w", err)
		}
		i.ViewID = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: field time_in_view_ms: %w", err)
		}
		i.TimeInViewMs = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: field active_time_in_view_ms: %w", err)
		}
		i.ActiveTimeInViewMs = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: field height_to_viewport_ratio_permille: %w", err)
		}
		i.HeightToViewportRatioPermille = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputMessageReadMetric#402b4495: field seen_range_ratio_permille: %w", err)
		}
		i.SeenRangeRatioPermille = value
	}
	return nil
}

// GetMsgID returns value of MsgID field.
func (i *InputMessageReadMetric) GetMsgID() (value int) {
	if i == nil {
		return
	}
	return i.MsgID
}

// GetViewID returns value of ViewID field.
func (i *InputMessageReadMetric) GetViewID() (value int64) {
	if i == nil {
		return
	}
	return i.ViewID
}

// GetTimeInViewMs returns value of TimeInViewMs field.
func (i *InputMessageReadMetric) GetTimeInViewMs() (value int) {
	if i == nil {
		return
	}
	return i.TimeInViewMs
}

// GetActiveTimeInViewMs returns value of ActiveTimeInViewMs field.
func (i *InputMessageReadMetric) GetActiveTimeInViewMs() (value int) {
	if i == nil {
		return
	}
	return i.ActiveTimeInViewMs
}

// GetHeightToViewportRatioPermille returns value of HeightToViewportRatioPermille field.
func (i *InputMessageReadMetric) GetHeightToViewportRatioPermille() (value int) {
	if i == nil {
		return
	}
	return i.HeightToViewportRatioPermille
}

// GetSeenRangeRatioPermille returns value of SeenRangeRatioPermille field.
func (i *InputMessageReadMetric) GetSeenRangeRatioPermille() (value int) {
	if i == nil {
		return
	}
	return i.SeenRangeRatioPermille
}
