// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// InputBotInlineMessageID represents TL type `inputBotInlineMessageID#890c3d89`.
// Represents a sent inline message from the perspective of a bot (legacy constructor)
//
// See https://core.telegram.org/constructor/inputBotInlineMessageID for reference.
type InputBotInlineMessageID struct {
	// DC ID to use when working with this inline message
	DCID int
	// ID of message, contains both the (32-bit, legacy) owner ID and the message ID, used
	// only for Bot API backwards compatibility with 32-bit user ID.
	ID int64
	// Access hash of message
	AccessHash int64
}

// InputBotInlineMessageIDTypeID is TL type id of InputBotInlineMessageID.
const InputBotInlineMessageIDTypeID = 0x890c3d89

// construct implements constructor of InputBotInlineMessageIDClass.
func (i InputBotInlineMessageID) construct() InputBotInlineMessageIDClass { return &i }

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

	_ InputBotInlineMessageIDClass = &InputBotInlineMessageID{}
)

func (i *InputBotInlineMessageID) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.DCID == 0) {
		return false
	}
	if !(i.ID == 0) {
		return false
	}
	if !(i.AccessHash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills InputBotInlineMessageID from given interface.
func (i *InputBotInlineMessageID) FillFrom(from interface {
	GetDCID() (value int)
	GetID() (value int64)
	GetAccessHash() (value int64)
}) {
	i.DCID = from.GetDCID()
	i.ID = from.GetID()
	i.AccessHash = from.GetAccessHash()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputBotInlineMessageID) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputBotInlineMessageID",
		ID:   InputBotInlineMessageIDTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputBotInlineMessageID) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBotInlineMessageID#890c3d89 as nil")
	}
	b.PutID(InputBotInlineMessageIDTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputBotInlineMessageID) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBotInlineMessageID#890c3d89 as nil")
	}
	b.PutInt(i.DCID)
	b.PutLong(i.ID)
	b.PutLong(i.AccessHash)
	return nil
}

// Decode implements bin.Decoder.
func (i *InputBotInlineMessageID) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputBotInlineMessageID#890c3d89 to nil")
	}
	if err := b.ConsumeID(InputBotInlineMessageIDTypeID); err != nil {
		return fmt.Errorf("unable to decode inputBotInlineMessageID#890c3d89: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputBotInlineMessageID) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputBotInlineMessageID#890c3d89 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID#890c3d89: field dc_id: %w", err)
		}
		i.DCID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID#890c3d89: field id: %w", err)
		}
		i.ID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID#890c3d89: field access_hash: %w", err)
		}
		i.AccessHash = value
	}
	return nil
}

// GetDCID returns value of DCID field.
func (i *InputBotInlineMessageID) GetDCID() (value int) {
	if i == nil {
		return
	}
	return i.DCID
}

// GetID returns value of ID field.
func (i *InputBotInlineMessageID) GetID() (value int64) {
	if i == nil {
		return
	}
	return i.ID
}

// GetAccessHash returns value of AccessHash field.
func (i *InputBotInlineMessageID) GetAccessHash() (value int64) {
	if i == nil {
		return
	}
	return i.AccessHash
}

// InputBotInlineMessageID64 represents TL type `inputBotInlineMessageID64#b6d915d7`.
// Represents a sent inline message from the perspective of a bot
//
// See https://core.telegram.org/constructor/inputBotInlineMessageID64 for reference.
type InputBotInlineMessageID64 struct {
	// DC ID to use when working with this inline message
	DCID int
	// ID of the owner of this message
	OwnerID int64
	// ID of message
	ID int
	// Access hash of message
	AccessHash int64
}

// InputBotInlineMessageID64TypeID is TL type id of InputBotInlineMessageID64.
const InputBotInlineMessageID64TypeID = 0xb6d915d7

// construct implements constructor of InputBotInlineMessageIDClass.
func (i InputBotInlineMessageID64) construct() InputBotInlineMessageIDClass { return &i }

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

	_ InputBotInlineMessageIDClass = &InputBotInlineMessageID64{}
)

func (i *InputBotInlineMessageID64) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.DCID == 0) {
		return false
	}
	if !(i.OwnerID == 0) {
		return false
	}
	if !(i.ID == 0) {
		return false
	}
	if !(i.AccessHash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills InputBotInlineMessageID64 from given interface.
func (i *InputBotInlineMessageID64) FillFrom(from interface {
	GetDCID() (value int)
	GetOwnerID() (value int64)
	GetID() (value int)
	GetAccessHash() (value int64)
}) {
	i.DCID = from.GetDCID()
	i.OwnerID = from.GetOwnerID()
	i.ID = from.GetID()
	i.AccessHash = from.GetAccessHash()
}

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

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

// TypeInfo returns info about TL type.
func (i *InputBotInlineMessageID64) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputBotInlineMessageID64",
		ID:   InputBotInlineMessageID64TypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
		{
			Name:       "OwnerID",
			SchemaName: "owner_id",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputBotInlineMessageID64) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBotInlineMessageID64#b6d915d7 as nil")
	}
	b.PutID(InputBotInlineMessageID64TypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputBotInlineMessageID64) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBotInlineMessageID64#b6d915d7 as nil")
	}
	b.PutInt(i.DCID)
	b.PutLong(i.OwnerID)
	b.PutInt(i.ID)
	b.PutLong(i.AccessHash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (i *InputBotInlineMessageID64) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputBotInlineMessageID64#b6d915d7 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID64#b6d915d7: field dc_id: %w", err)
		}
		i.DCID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID64#b6d915d7: field owner_id: %w", err)
		}
		i.OwnerID = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID64#b6d915d7: field id: %w", err)
		}
		i.ID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode inputBotInlineMessageID64#b6d915d7: field access_hash: %w", err)
		}
		i.AccessHash = value
	}
	return nil
}

// GetDCID returns value of DCID field.
func (i *InputBotInlineMessageID64) GetDCID() (value int) {
	if i == nil {
		return
	}
	return i.DCID
}

// GetOwnerID returns value of OwnerID field.
func (i *InputBotInlineMessageID64) GetOwnerID() (value int64) {
	if i == nil {
		return
	}
	return i.OwnerID
}

// GetID returns value of ID field.
func (i *InputBotInlineMessageID64) GetID() (value int) {
	if i == nil {
		return
	}
	return i.ID
}

// GetAccessHash returns value of AccessHash field.
func (i *InputBotInlineMessageID64) GetAccessHash() (value int64) {
	if i == nil {
		return
	}
	return i.AccessHash
}

// InputBotInlineMessageIDClassName is schema name of InputBotInlineMessageIDClass.
const InputBotInlineMessageIDClassName = "InputBotInlineMessageID"

// InputBotInlineMessageIDClass represents InputBotInlineMessageID generic type.
//
// See https://core.telegram.org/type/InputBotInlineMessageID for reference.
//
// Example:
//
//	g, err := tg.DecodeInputBotInlineMessageID(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.InputBotInlineMessageID: // inputBotInlineMessageID#890c3d89
//	case *tg.InputBotInlineMessageID64: // inputBotInlineMessageID64#b6d915d7
//	default: panic(v)
//	}
type InputBotInlineMessageIDClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() InputBotInlineMessageIDClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// DC ID to use when working with this inline message
	GetDCID() (value int)

	// Access hash of message
	GetAccessHash() (value int64)
}

// DecodeInputBotInlineMessageID implements binary de-serialization for InputBotInlineMessageIDClass.
func DecodeInputBotInlineMessageID(buf *bin.Buffer) (InputBotInlineMessageIDClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case InputBotInlineMessageIDTypeID:
		// Decoding inputBotInlineMessageID#890c3d89.
		v := InputBotInlineMessageID{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputBotInlineMessageIDClass: %w", err)
		}
		return &v, nil
	case InputBotInlineMessageID64TypeID:
		// Decoding inputBotInlineMessageID64#b6d915d7.
		v := InputBotInlineMessageID64{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode InputBotInlineMessageIDClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode InputBotInlineMessageIDClass: %w", bin.NewUnexpectedID(id))
	}
}

// InputBotInlineMessageID boxes the InputBotInlineMessageIDClass providing a helper.
type InputBotInlineMessageIDBox struct {
	InputBotInlineMessageID InputBotInlineMessageIDClass
}

// Decode implements bin.Decoder for InputBotInlineMessageIDBox.
func (b *InputBotInlineMessageIDBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode InputBotInlineMessageIDBox to nil")
	}
	v, err := DecodeInputBotInlineMessageID(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.InputBotInlineMessageID = v
	return nil
}

// Encode implements bin.Encode for InputBotInlineMessageIDBox.
func (b *InputBotInlineMessageIDBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.InputBotInlineMessageID == nil {
		return fmt.Errorf("unable to encode InputBotInlineMessageIDClass as nil")
	}
	return b.InputBotInlineMessageID.Encode(buf)
}
