// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// MessagesGetHistoryRequest represents TL type `messages.getHistory#4423e6c5`.
// Returns the conversation history with one interlocutor / within a chat
//
// See https://core.telegram.org/method/messages.getHistory for reference.
type MessagesGetHistoryRequest struct {
	// Target peer
	Peer InputPeerClass
	// Only return messages starting from the specified message ID
	OffsetID int
	// Only return messages sent before the specified date
	OffsetDate int
	// Number of list elements to be skipped, negative values are also accepted.
	AddOffset int
	// Number of results to return
	Limit int
	// If a positive value was transferred, the method will return only messages with IDs
	// less than max_id
	MaxID int
	// If a positive value was transferred, the method will return only messages with IDs
	// more than min_id
	MinID int
	// Result hash¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Hash int64
}

// MessagesGetHistoryRequestTypeID is TL type id of MessagesGetHistoryRequest.
const MessagesGetHistoryRequestTypeID = 0x4423e6c5

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

func ( *MessagesGetHistoryRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.OffsetID == 0) {
		return false
	}
	if !(.OffsetDate == 0) {
		return false
	}
	if !(.AddOffset == 0) {
		return false
	}
	if !(.Limit == 0) {
		return false
	}
	if !(.MaxID == 0) {
		return false
	}
	if !(.MinID == 0) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesGetHistoryRequest from given interface.
func ( *MessagesGetHistoryRequest) ( interface {
	() ( InputPeerClass)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int64)
}) {
	.Peer = .()
	.OffsetID = .()
	.OffsetDate = .()
	.AddOffset = .()
	.Limit = .()
	.MaxID = .()
	.MinID = .()
	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesGetHistoryRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.getHistory",
		ID:   MessagesGetHistoryRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "OffsetID",
			SchemaName: "offset_id",
		},
		{
			Name:       "OffsetDate",
			SchemaName: "offset_date",
		},
		{
			Name:       "AddOffset",
			SchemaName: "add_offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
		{
			Name:       "MaxID",
			SchemaName: "max_id",
		},
		{
			Name:       "MinID",
			SchemaName: "min_id",
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesGetHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getHistory#4423e6c5 as nil")
	}
	.PutID(MessagesGetHistoryRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesGetHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getHistory#4423e6c5 as nil")
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.getHistory#4423e6c5: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.getHistory#4423e6c5: field peer: %w", )
	}
	.PutInt(.OffsetID)
	.PutInt(.OffsetDate)
	.PutInt(.AddOffset)
	.PutInt(.Limit)
	.PutInt(.MaxID)
	.PutInt(.MinID)
	.PutLong(.Hash)
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesGetHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.getHistory#4423e6c5 to nil")
	}
	if  := .ConsumeID(MessagesGetHistoryRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesGetHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.getHistory#4423e6c5 to nil")
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field offset_id: %w", )
		}
		.OffsetID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field offset_date: %w", )
		}
		.OffsetDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field add_offset: %w", )
		}
		.AddOffset = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field limit: %w", )
		}
		.Limit = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field max_id: %w", )
		}
		.MaxID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field min_id: %w", )
		}
		.MinID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getHistory#4423e6c5: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

// GetPeer returns value of Peer field.
func ( *MessagesGetHistoryRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// GetOffsetID returns value of OffsetID field.
func ( *MessagesGetHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .OffsetID
}

// GetOffsetDate returns value of OffsetDate field.
func ( *MessagesGetHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .OffsetDate
}

// GetAddOffset returns value of AddOffset field.
func ( *MessagesGetHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .AddOffset
}

// GetLimit returns value of Limit field.
func ( *MessagesGetHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .Limit
}

// GetMaxID returns value of MaxID field.
func ( *MessagesGetHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .MaxID
}

// GetMinID returns value of MinID field.
func ( *MessagesGetHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .MinID
}

// GetHash returns value of Hash field.
func ( *MessagesGetHistoryRequest) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}

// MessagesGetHistory invokes method messages.getHistory#4423e6c5 returning error if any.
// Returns the conversation history with one interlocutor / within a chat
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	406 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	400 CHAT_ID_INVALID: The provided chat id is invalid.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/messages.getHistory for reference.
func ( *Client) ( context.Context,  *MessagesGetHistoryRequest) (MessagesMessagesClass, error) {
	var  MessagesMessagesBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .Messages, nil
}