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

// MessagesHistoryImport represents TL type `messages.historyImport#1662af0b`.
// ID of a specific chat import session, click here for more info »¹.
//
// Links:
//  1. https://core.telegram.org/api/import
//
// See https://core.telegram.org/constructor/messages.historyImport for reference.
type MessagesHistoryImport struct {
	// History import ID¹
	//
	// Links:
	//  1) https://core.telegram.org/api/import
	ID int64
}

// MessagesHistoryImportTypeID is TL type id of MessagesHistoryImport.
const MessagesHistoryImportTypeID = 0x1662af0b

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

func (h *MessagesHistoryImport) Zero() bool {
	if h == nil {
		return true
	}
	if !(h.ID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesHistoryImport from given interface.
func (h *MessagesHistoryImport) FillFrom(from interface {
	GetID() (value int64)
}) {
	h.ID = from.GetID()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesHistoryImport) TypeName() string {
	return "messages.historyImport"
}

// TypeInfo returns info about TL type.
func (h *MessagesHistoryImport) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.historyImport",
		ID:   MessagesHistoryImportTypeID,
	}
	if h == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (h *MessagesHistoryImport) Encode(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't encode messages.historyImport#1662af0b as nil")
	}
	b.PutID(MessagesHistoryImportTypeID)
	return h.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (h *MessagesHistoryImport) EncodeBare(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't encode messages.historyImport#1662af0b as nil")
	}
	b.PutLong(h.ID)
	return nil
}

// Decode implements bin.Decoder.
func (h *MessagesHistoryImport) Decode(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't decode messages.historyImport#1662af0b to nil")
	}
	if err := b.ConsumeID(MessagesHistoryImportTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.historyImport#1662af0b: %w", err)
	}
	return h.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (h *MessagesHistoryImport) DecodeBare(b *bin.Buffer) error {
	if h == nil {
		return fmt.Errorf("can't decode messages.historyImport#1662af0b to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.historyImport#1662af0b: field id: %w", err)
		}
		h.ID = value
	}
	return nil
}

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