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

// PeerUser represents TL type `peerUser#59511722`.
// Chat partner
//
// See https://core.telegram.org/constructor/peerUser for reference.
type PeerUser struct {
	// User identifier
	UserID int64
}

// PeerUserTypeID is TL type id of PeerUser.
const PeerUserTypeID = 0x59511722

// construct implements constructor of PeerClass.
func ( PeerUser) () PeerClass { return & }

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

	_ PeerClass = &PeerUser{}
)

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

	return true
}

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

// FillFrom fills PeerUser from given interface.
func ( *PeerUser) ( interface {
	() ( int64)
}) {
	.UserID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PeerUser) () tdp.Type {
	 := tdp.Type{
		Name: "peerUser",
		ID:   PeerUserTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PeerUser) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerUser#59511722 as nil")
	}
	.PutID(PeerUserTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerUser) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerUser#59511722 as nil")
	}
	.PutLong(.UserID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerUser) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerUser#59511722 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode peerUser#59511722: field user_id: %w", )
		}
		.UserID = 
	}
	return nil
}

// GetUserID returns value of UserID field.
func ( *PeerUser) () ( int64) {
	if  == nil {
		return
	}
	return .UserID
}

// PeerChat represents TL type `peerChat#36c6019a`.
// Group.
//
// See https://core.telegram.org/constructor/peerChat for reference.
type PeerChat struct {
	// Group identifier
	ChatID int64
}

// PeerChatTypeID is TL type id of PeerChat.
const PeerChatTypeID = 0x36c6019a

// construct implements constructor of PeerClass.
func ( PeerChat) () PeerClass { return & }

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

	_ PeerClass = &PeerChat{}
)

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

	return true
}

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

// FillFrom fills PeerChat from given interface.
func ( *PeerChat) ( interface {
	() ( int64)
}) {
	.ChatID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PeerChat) () tdp.Type {
	 := tdp.Type{
		Name: "peerChat",
		ID:   PeerChatTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PeerChat) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerChat#36c6019a as nil")
	}
	.PutID(PeerChatTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerChat) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerChat#36c6019a as nil")
	}
	.PutLong(.ChatID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerChat) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerChat#36c6019a to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode peerChat#36c6019a: field chat_id: %w", )
		}
		.ChatID = 
	}
	return nil
}

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

// PeerChannel represents TL type `peerChannel#a2a5371e`.
// Channel/supergroup
//
// See https://core.telegram.org/constructor/peerChannel for reference.
type PeerChannel struct {
	// Channel ID
	ChannelID int64
}

// PeerChannelTypeID is TL type id of PeerChannel.
const PeerChannelTypeID = 0xa2a5371e

// construct implements constructor of PeerClass.
func ( PeerChannel) () PeerClass { return & }

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

	_ PeerClass = &PeerChannel{}
)

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

	return true
}

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

// FillFrom fills PeerChannel from given interface.
func ( *PeerChannel) ( interface {
	() ( int64)
}) {
	.ChannelID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PeerChannel) () tdp.Type {
	 := tdp.Type{
		Name: "peerChannel",
		ID:   PeerChannelTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ChannelID",
			SchemaName: "channel_id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PeerChannel) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerChannel#a2a5371e as nil")
	}
	.PutID(PeerChannelTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerChannel) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerChannel#a2a5371e as nil")
	}
	.PutLong(.ChannelID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerChannel) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerChannel#a2a5371e to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode peerChannel#a2a5371e: field channel_id: %w", )
		}
		.ChannelID = 
	}
	return nil
}

// GetChannelID returns value of ChannelID field.
func ( *PeerChannel) () ( int64) {
	if  == nil {
		return
	}
	return .ChannelID
}

// PeerClassName is schema name of PeerClass.
const PeerClassName = "Peer"

// PeerClass represents Peer generic type.
//
// See https://core.telegram.org/type/Peer for reference.
//
// Example:
//
//	g, err := tg.DecodePeer(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PeerUser: // peerUser#59511722
//	case *tg.PeerChat: // peerChat#36c6019a
//	case *tg.PeerChannel: // peerChannel#a2a5371e
//	default: panic(v)
//	}
type PeerClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PeerClass

	// 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 PeerChat to InputPeerChat.
func ( *PeerChat) () *InputPeerChat {
	 := new(InputPeerChat)
	.ChatID = .GetChatID()

	return 
}

// DecodePeer implements binary de-serialization for PeerClass.
func ( *bin.Buffer) (PeerClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case PeerUserTypeID:
		// Decoding peerUser#59511722.
		 := PeerUser{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PeerClass: %w", )
		}
		return &, nil
	case PeerChatTypeID:
		// Decoding peerChat#36c6019a.
		 := PeerChat{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PeerClass: %w", )
		}
		return &, nil
	case PeerChannelTypeID:
		// Decoding peerChannel#a2a5371e.
		 := PeerChannel{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PeerClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode PeerClass: %w", bin.NewUnexpectedID())
	}
}

// Peer boxes the PeerClass providing a helper.
type PeerBox struct {
	Peer PeerClass
}

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

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