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

// DialogPeer represents TL type `dialogPeer#e56dbf05`.
// Peer
//
// See https://core.telegram.org/constructor/dialogPeer for reference.
type DialogPeer struct {
	// Peer
	Peer PeerClass
}

// DialogPeerTypeID is TL type id of DialogPeer.
const DialogPeerTypeID = 0xe56dbf05

// construct implements constructor of DialogPeerClass.
func ( DialogPeer) () DialogPeerClass { return & }

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

	_ DialogPeerClass = &DialogPeer{}
)

func ( *DialogPeer) () bool {
	if  == nil {
		return true
	}
	if !(.Peer == nil) {
		return false
	}

	return true
}

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

// FillFrom fills DialogPeer from given interface.
func ( *DialogPeer) ( interface {
	() ( PeerClass)
}) {
	.Peer = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *DialogPeer) () tdp.Type {
	 := tdp.Type{
		Name: "dialogPeer",
		ID:   DialogPeerTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *DialogPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode dialogPeer#e56dbf05 as nil")
	}
	.PutID(DialogPeerTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *DialogPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode dialogPeer#e56dbf05 as nil")
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode dialogPeer#e56dbf05: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode dialogPeer#e56dbf05: field peer: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *DialogPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode dialogPeer#e56dbf05 to nil")
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode dialogPeer#e56dbf05: field peer: %w", )
		}
		.Peer = 
	}
	return nil
}

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

// DialogPeerFolder represents TL type `dialogPeerFolder#514519e2`.
// Peer folderĀ¹
//
// Links:
//  1. https://core.telegram.org/api/folders#peer-folders
//
// See https://core.telegram.org/constructor/dialogPeerFolder for reference.
type DialogPeerFolder struct {
	// Peer folder ID, for more info click hereĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/api/folders#peer-folders
	FolderID int
}

// DialogPeerFolderTypeID is TL type id of DialogPeerFolder.
const DialogPeerFolderTypeID = 0x514519e2

// construct implements constructor of DialogPeerClass.
func ( DialogPeerFolder) () DialogPeerClass { return & }

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

	_ DialogPeerClass = &DialogPeerFolder{}
)

func ( *DialogPeerFolder) () bool {
	if  == nil {
		return true
	}
	if !(.FolderID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills DialogPeerFolder from given interface.
func ( *DialogPeerFolder) ( interface {
	() ( int)
}) {
	.FolderID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *DialogPeerFolder) () tdp.Type {
	 := tdp.Type{
		Name: "dialogPeerFolder",
		ID:   DialogPeerFolderTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "FolderID",
			SchemaName: "folder_id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *DialogPeerFolder) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode dialogPeerFolder#514519e2 as nil")
	}
	.PutID(DialogPeerFolderTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *DialogPeerFolder) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode dialogPeerFolder#514519e2 as nil")
	}
	.PutInt(.FolderID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *DialogPeerFolder) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode dialogPeerFolder#514519e2 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode dialogPeerFolder#514519e2: field folder_id: %w", )
		}
		.FolderID = 
	}
	return nil
}

// GetFolderID returns value of FolderID field.
func ( *DialogPeerFolder) () ( int) {
	if  == nil {
		return
	}
	return .FolderID
}

// DialogPeerClassName is schema name of DialogPeerClass.
const DialogPeerClassName = "DialogPeer"

// DialogPeerClass represents DialogPeer generic type.
//
// See https://core.telegram.org/type/DialogPeer for reference.
//
// Example:
//
//	g, err := tg.DecodeDialogPeer(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.DialogPeer: // dialogPeer#e56dbf05
//	case *tg.DialogPeerFolder: // dialogPeerFolder#514519e2
//	default: panic(v)
//	}
type DialogPeerClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() DialogPeerClass

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

// AsInput tries to map DialogPeerFolder to InputDialogPeerFolder.
func ( *DialogPeerFolder) () *InputDialogPeerFolder {
	 := new(InputDialogPeerFolder)
	.FolderID = .GetFolderID()

	return 
}

// DecodeDialogPeer implements binary de-serialization for DialogPeerClass.
func ( *bin.Buffer) (DialogPeerClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case DialogPeerTypeID:
		// Decoding dialogPeer#e56dbf05.
		 := DialogPeer{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode DialogPeerClass: %w", )
		}
		return &, nil
	case DialogPeerFolderTypeID:
		// Decoding dialogPeerFolder#514519e2.
		 := DialogPeerFolder{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode DialogPeerClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode DialogPeerClass: %w", bin.NewUnexpectedID())
	}
}

// DialogPeer boxes the DialogPeerClass providing a helper.
type DialogPeerBox struct {
	DialogPeer DialogPeerClass
}

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

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