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

// EncryptedMessage represents TL type `encryptedMessage#ed18c118`.
// Encrypted message.
//
// See https://core.telegram.org/constructor/encryptedMessage for reference.
type EncryptedMessage struct {
	// Random message ID, assigned by the author of message
	RandomID int64
	// ID of encrypted chat
	ChatID int
	// Date of sending
	Date int
	// TL-serialization of DecryptedMessage¹ type, encrypted with the key created at chat
	// initialization
	//
	// Links:
	//  1) https://core.telegram.org/type/DecryptedMessage
	Bytes []byte
	// Attached encrypted file
	File EncryptedFileClass
}

// EncryptedMessageTypeID is TL type id of EncryptedMessage.
const EncryptedMessageTypeID = 0xed18c118

// construct implements constructor of EncryptedMessageClass.
func ( EncryptedMessage) () EncryptedMessageClass { return & }

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

	_ EncryptedMessageClass = &EncryptedMessage{}
)

func ( *EncryptedMessage) () bool {
	if  == nil {
		return true
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.ChatID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Bytes == nil) {
		return false
	}
	if !(.File == nil) {
		return false
	}

	return true
}

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

// FillFrom fills EncryptedMessage from given interface.
func ( *EncryptedMessage) ( interface {
	() ( int64)
	() ( int)
	() ( int)
	() ( []byte)
	() ( EncryptedFileClass)
}) {
	.RandomID = .()
	.ChatID = .()
	.Date = .()
	.Bytes = .()
	.File = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *EncryptedMessage) () tdp.Type {
	 := tdp.Type{
		Name: "encryptedMessage",
		ID:   EncryptedMessageTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Bytes",
			SchemaName: "bytes",
		},
		{
			Name:       "File",
			SchemaName: "file",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *EncryptedMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode encryptedMessage#ed18c118 as nil")
	}
	.PutID(EncryptedMessageTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *EncryptedMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode encryptedMessage#ed18c118 as nil")
	}
	.PutLong(.RandomID)
	.PutInt(.ChatID)
	.PutInt(.Date)
	.PutBytes(.Bytes)
	if .File == nil {
		return fmt.Errorf("unable to encode encryptedMessage#ed18c118: field file is nil")
	}
	if  := .File.Encode();  != nil {
		return fmt.Errorf("unable to encode encryptedMessage#ed18c118: field file: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *EncryptedMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode encryptedMessage#ed18c118 to nil")
	}
	if  := .ConsumeID(EncryptedMessageTypeID);  != nil {
		return fmt.Errorf("unable to decode encryptedMessage#ed18c118: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *EncryptedMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode encryptedMessage#ed18c118 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessage#ed18c118: field random_id: %w", )
		}
		.RandomID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessage#ed18c118: field chat_id: %w", )
		}
		.ChatID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessage#ed18c118: field date: %w", )
		}
		.Date = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessage#ed18c118: field bytes: %w", )
		}
		.Bytes = 
	}
	{
		,  := DecodeEncryptedFile()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessage#ed18c118: field file: %w", )
		}
		.File = 
	}
	return nil
}

// GetRandomID returns value of RandomID field.
func ( *EncryptedMessage) () ( int64) {
	if  == nil {
		return
	}
	return .RandomID
}

// GetChatID returns value of ChatID field.
func ( *EncryptedMessage) () ( int) {
	if  == nil {
		return
	}
	return .ChatID
}

// GetDate returns value of Date field.
func ( *EncryptedMessage) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// GetBytes returns value of Bytes field.
func ( *EncryptedMessage) () ( []byte) {
	if  == nil {
		return
	}
	return .Bytes
}

// GetFile returns value of File field.
func ( *EncryptedMessage) () ( EncryptedFileClass) {
	if  == nil {
		return
	}
	return .File
}

// EncryptedMessageService represents TL type `encryptedMessageService#23734b06`.
// Encrypted service message
//
// See https://core.telegram.org/constructor/encryptedMessageService for reference.
type EncryptedMessageService struct {
	// Random message ID, assigned by the author of message
	RandomID int64
	// ID of encrypted chat
	ChatID int
	// Date of sending
	Date int
	// TL-serialization of the DecryptedMessage¹ type, encrypted with the key created at
	// chat initialization
	//
	// Links:
	//  1) https://core.telegram.org/type/DecryptedMessage
	Bytes []byte
}

// EncryptedMessageServiceTypeID is TL type id of EncryptedMessageService.
const EncryptedMessageServiceTypeID = 0x23734b06

// construct implements constructor of EncryptedMessageClass.
func ( EncryptedMessageService) () EncryptedMessageClass { return & }

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

	_ EncryptedMessageClass = &EncryptedMessageService{}
)

func ( *EncryptedMessageService) () bool {
	if  == nil {
		return true
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.ChatID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Bytes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills EncryptedMessageService from given interface.
func ( *EncryptedMessageService) ( interface {
	() ( int64)
	() ( int)
	() ( int)
	() ( []byte)
}) {
	.RandomID = .()
	.ChatID = .()
	.Date = .()
	.Bytes = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *EncryptedMessageService) () tdp.Type {
	 := tdp.Type{
		Name: "encryptedMessageService",
		ID:   EncryptedMessageServiceTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Bytes",
			SchemaName: "bytes",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *EncryptedMessageService) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode encryptedMessageService#23734b06 as nil")
	}
	.PutID(EncryptedMessageServiceTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *EncryptedMessageService) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode encryptedMessageService#23734b06 as nil")
	}
	.PutLong(.RandomID)
	.PutInt(.ChatID)
	.PutInt(.Date)
	.PutBytes(.Bytes)
	return nil
}

// Decode implements bin.Decoder.
func ( *EncryptedMessageService) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode encryptedMessageService#23734b06 to nil")
	}
	if  := .ConsumeID(EncryptedMessageServiceTypeID);  != nil {
		return fmt.Errorf("unable to decode encryptedMessageService#23734b06: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *EncryptedMessageService) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode encryptedMessageService#23734b06 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessageService#23734b06: field random_id: %w", )
		}
		.RandomID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessageService#23734b06: field chat_id: %w", )
		}
		.ChatID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessageService#23734b06: field date: %w", )
		}
		.Date = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode encryptedMessageService#23734b06: field bytes: %w", )
		}
		.Bytes = 
	}
	return nil
}

// GetRandomID returns value of RandomID field.
func ( *EncryptedMessageService) () ( int64) {
	if  == nil {
		return
	}
	return .RandomID
}

// GetChatID returns value of ChatID field.
func ( *EncryptedMessageService) () ( int) {
	if  == nil {
		return
	}
	return .ChatID
}

// GetDate returns value of Date field.
func ( *EncryptedMessageService) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// GetBytes returns value of Bytes field.
func ( *EncryptedMessageService) () ( []byte) {
	if  == nil {
		return
	}
	return .Bytes
}

// EncryptedMessageClassName is schema name of EncryptedMessageClass.
const EncryptedMessageClassName = "EncryptedMessage"

// EncryptedMessageClass represents EncryptedMessage generic type.
//
// See https://core.telegram.org/type/EncryptedMessage for reference.
//
// Example:
//
//	g, err := tg.DecodeEncryptedMessage(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.EncryptedMessage: // encryptedMessage#ed18c118
//	case *tg.EncryptedMessageService: // encryptedMessageService#23734b06
//	default: panic(v)
//	}
type EncryptedMessageClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() EncryptedMessageClass

	// 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

	// Random message ID, assigned by the author of message
	GetRandomID() (value int64)

	// ID of encrypted chat
	GetChatID() (value int)

	// Date of sending
	GetDate() (value int)

	// TL-serialization of DecryptedMessage¹ type, encrypted with the key created at chat
	// initialization
	//
	// Links:
	//  1) https://core.telegram.org/type/DecryptedMessage
	GetBytes() (value []byte)
}

// DecodeEncryptedMessage implements binary de-serialization for EncryptedMessageClass.
func ( *bin.Buffer) (EncryptedMessageClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case EncryptedMessageTypeID:
		// Decoding encryptedMessage#ed18c118.
		 := EncryptedMessage{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode EncryptedMessageClass: %w", )
		}
		return &, nil
	case EncryptedMessageServiceTypeID:
		// Decoding encryptedMessageService#23734b06.
		 := EncryptedMessageService{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode EncryptedMessageClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode EncryptedMessageClass: %w", bin.NewUnexpectedID())
	}
}

// EncryptedMessage boxes the EncryptedMessageClass providing a helper.
type EncryptedMessageBox struct {
	EncryptedMessage EncryptedMessageClass
}

// Decode implements bin.Decoder for EncryptedMessageBox.
func ( *EncryptedMessageBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode EncryptedMessageBox to nil")
	}
	,  := DecodeEncryptedMessage()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.EncryptedMessage = 
	return nil
}

// Encode implements bin.Encode for EncryptedMessageBox.
func ( *EncryptedMessageBox) ( *bin.Buffer) error {
	if  == nil || .EncryptedMessage == nil {
		return fmt.Errorf("unable to encode EncryptedMessageClass as nil")
	}
	return .EncryptedMessage.Encode()
}