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

// PeerLocated represents TL type `peerLocated#ca461b5d`.
// Peer geolocated nearby
//
// See https://core.telegram.org/constructor/peerLocated for reference.
type PeerLocated struct {
	// Peer
	Peer PeerClass
	// Validity period of current data
	Expires int
	// Distance from the peer in meters
	Distance int
}

// PeerLocatedTypeID is TL type id of PeerLocated.
const PeerLocatedTypeID = 0xca461b5d

// construct implements constructor of PeerLocatedClass.
func ( PeerLocated) () PeerLocatedClass { return & }

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

	_ PeerLocatedClass = &PeerLocated{}
)

func ( *PeerLocated) () bool {
	if  == nil {
		return true
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Expires == 0) {
		return false
	}
	if !(.Distance == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PeerLocated from given interface.
func ( *PeerLocated) ( interface {
	() ( PeerClass)
	() ( int)
	() ( int)
}) {
	.Peer = .()
	.Expires = .()
	.Distance = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PeerLocated) () tdp.Type {
	 := tdp.Type{
		Name: "peerLocated",
		ID:   PeerLocatedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Expires",
			SchemaName: "expires",
		},
		{
			Name:       "Distance",
			SchemaName: "distance",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PeerLocated) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerLocated#ca461b5d as nil")
	}
	.PutID(PeerLocatedTypeID)
	return .EncodeBare()
}

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

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerLocated) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerLocated#ca461b5d to nil")
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode peerLocated#ca461b5d: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerLocated#ca461b5d: field expires: %w", )
		}
		.Expires = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerLocated#ca461b5d: field distance: %w", )
		}
		.Distance = 
	}
	return nil
}

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

// GetExpires returns value of Expires field.
func ( *PeerLocated) () ( int) {
	if  == nil {
		return
	}
	return .Expires
}

// GetDistance returns value of Distance field.
func ( *PeerLocated) () ( int) {
	if  == nil {
		return
	}
	return .Distance
}

// PeerSelfLocated represents TL type `peerSelfLocated#f8ec284b`.
// Current peer
//
// See https://core.telegram.org/constructor/peerSelfLocated for reference.
type PeerSelfLocated struct {
	// Expiry of geolocation info for current peer
	Expires int
}

// PeerSelfLocatedTypeID is TL type id of PeerSelfLocated.
const PeerSelfLocatedTypeID = 0xf8ec284b

// construct implements constructor of PeerLocatedClass.
func ( PeerSelfLocated) () PeerLocatedClass { return & }

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

	_ PeerLocatedClass = &PeerSelfLocated{}
)

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

	return true
}

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

// FillFrom fills PeerSelfLocated from given interface.
func ( *PeerSelfLocated) ( interface {
	() ( int)
}) {
	.Expires = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PeerSelfLocated) () tdp.Type {
	 := tdp.Type{
		Name: "peerSelfLocated",
		ID:   PeerSelfLocatedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Expires",
			SchemaName: "expires",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PeerSelfLocated) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerSelfLocated#f8ec284b as nil")
	}
	.PutID(PeerSelfLocatedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerSelfLocated) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerSelfLocated#f8ec284b as nil")
	}
	.PutInt(.Expires)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerSelfLocated) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerSelfLocated#f8ec284b to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerSelfLocated#f8ec284b: field expires: %w", )
		}
		.Expires = 
	}
	return nil
}

// GetExpires returns value of Expires field.
func ( *PeerSelfLocated) () ( int) {
	if  == nil {
		return
	}
	return .Expires
}

// PeerLocatedClassName is schema name of PeerLocatedClass.
const PeerLocatedClassName = "PeerLocated"

// PeerLocatedClass represents PeerLocated generic type.
//
// See https://core.telegram.org/type/PeerLocated for reference.
//
// Example:
//
//	g, err := tg.DecodePeerLocated(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PeerLocated: // peerLocated#ca461b5d
//	case *tg.PeerSelfLocated: // peerSelfLocated#f8ec284b
//	default: panic(v)
//	}
type PeerLocatedClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PeerLocatedClass

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

	// Validity period of current data
	GetExpires() (value int)
}

// DecodePeerLocated implements binary de-serialization for PeerLocatedClass.
func ( *bin.Buffer) (PeerLocatedClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case PeerLocatedTypeID:
		// Decoding peerLocated#ca461b5d.
		 := PeerLocated{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PeerLocatedClass: %w", )
		}
		return &, nil
	case PeerSelfLocatedTypeID:
		// Decoding peerSelfLocated#f8ec284b.
		 := PeerSelfLocated{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PeerLocatedClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode PeerLocatedClass: %w", bin.NewUnexpectedID())
	}
}

// PeerLocated boxes the PeerLocatedClass providing a helper.
type PeerLocatedBox struct {
	PeerLocated PeerLocatedClass
}

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

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