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

// GeoPointEmpty represents TL type `geoPointEmpty#1117dd5f`.
// Empty constructor.
//
// See https://core.telegram.org/constructor/geoPointEmpty for reference.
type GeoPointEmpty struct {
}

// GeoPointEmptyTypeID is TL type id of GeoPointEmpty.
const GeoPointEmptyTypeID = 0x1117dd5f

// construct implements constructor of GeoPointClass.
func ( GeoPointEmpty) () GeoPointClass { return & }

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

	_ GeoPointClass = &GeoPointEmpty{}
)

func ( *GeoPointEmpty) () bool {
	if  == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func ( *GeoPointEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "geoPointEmpty",
		ID:   GeoPointEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{}
	return 
}

// Encode implements bin.Encoder.
func ( *GeoPointEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode geoPointEmpty#1117dd5f as nil")
	}
	.PutID(GeoPointEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *GeoPointEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode geoPointEmpty#1117dd5f as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *GeoPointEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode geoPointEmpty#1117dd5f to nil")
	}
	return nil
}

// GeoPoint represents TL type `geoPoint#b2a2f663`.
// GeoPoint.
//
// See https://core.telegram.org/constructor/geoPoint for reference.
type GeoPoint struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Longitude
	Long float64
	// Latitude
	Lat float64
	// Access hash
	AccessHash int64
	// The estimated horizontal accuracy of the location, in meters; as defined by the sender.
	//
	// Use SetAccuracyRadius and GetAccuracyRadius helpers.
	AccuracyRadius int
}

// GeoPointTypeID is TL type id of GeoPoint.
const GeoPointTypeID = 0xb2a2f663

// construct implements constructor of GeoPointClass.
func ( GeoPoint) () GeoPointClass { return & }

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

	_ GeoPointClass = &GeoPoint{}
)

func ( *GeoPoint) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Long == 0) {
		return false
	}
	if !(.Lat == 0) {
		return false
	}
	if !(.AccessHash == 0) {
		return false
	}
	if !(.AccuracyRadius == 0) {
		return false
	}

	return true
}

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

// FillFrom fills GeoPoint from given interface.
func ( *GeoPoint) ( interface {
	() ( float64)
	() ( float64)
	() ( int64)
	() ( int,  bool)
}) {
	.Long = .()
	.Lat = .()
	.AccessHash = .()
	if ,  := .();  {
		.AccuracyRadius = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *GeoPoint) () tdp.Type {
	 := tdp.Type{
		Name: "geoPoint",
		ID:   GeoPointTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Long",
			SchemaName: "long",
		},
		{
			Name:       "Lat",
			SchemaName: "lat",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
		{
			Name:       "AccuracyRadius",
			SchemaName: "accuracy_radius",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *GeoPoint) () {
	if !(.AccuracyRadius == 0) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *GeoPoint) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode geoPoint#b2a2f663 as nil")
	}
	.PutID(GeoPointTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *GeoPoint) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode geoPoint#b2a2f663 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode geoPoint#b2a2f663: field flags: %w", )
	}
	.PutDouble(.Long)
	.PutDouble(.Lat)
	.PutLong(.AccessHash)
	if .Flags.Has(0) {
		.PutInt(.AccuracyRadius)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *GeoPoint) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode geoPoint#b2a2f663 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode geoPoint#b2a2f663: field flags: %w", )
		}
	}
	{
		,  := .Double()
		if  != nil {
			return fmt.Errorf("unable to decode geoPoint#b2a2f663: field long: %w", )
		}
		.Long = 
	}
	{
		,  := .Double()
		if  != nil {
			return fmt.Errorf("unable to decode geoPoint#b2a2f663: field lat: %w", )
		}
		.Lat = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode geoPoint#b2a2f663: field access_hash: %w", )
		}
		.AccessHash = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode geoPoint#b2a2f663: field accuracy_radius: %w", )
		}
		.AccuracyRadius = 
	}
	return nil
}

// GetLong returns value of Long field.
func ( *GeoPoint) () ( float64) {
	if  == nil {
		return
	}
	return .Long
}

// GetLat returns value of Lat field.
func ( *GeoPoint) () ( float64) {
	if  == nil {
		return
	}
	return .Lat
}

// GetAccessHash returns value of AccessHash field.
func ( *GeoPoint) () ( int64) {
	if  == nil {
		return
	}
	return .AccessHash
}

// SetAccuracyRadius sets value of AccuracyRadius conditional field.
func ( *GeoPoint) ( int) {
	.Flags.Set(0)
	.AccuracyRadius = 
}

// GetAccuracyRadius returns value of AccuracyRadius conditional field and
// boolean which is true if field was set.
func ( *GeoPoint) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .AccuracyRadius, true
}

// GeoPointClassName is schema name of GeoPointClass.
const GeoPointClassName = "GeoPoint"

// GeoPointClass represents GeoPoint generic type.
//
// See https://core.telegram.org/type/GeoPoint for reference.
//
// Example:
//
//	g, err := tg.DecodeGeoPoint(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.GeoPointEmpty: // geoPointEmpty#1117dd5f
//	case *tg.GeoPoint: // geoPoint#b2a2f663
//	default: panic(v)
//	}
type GeoPointClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() GeoPointClass

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

	// AsNotEmpty tries to map GeoPointClass to GeoPoint.
	AsNotEmpty() (*GeoPoint, bool)
}

// AsNotEmpty tries to map GeoPointEmpty to GeoPoint.
func ( *GeoPointEmpty) () (*GeoPoint, bool) {
	return nil, false
}

// AsNotEmpty tries to map GeoPoint to GeoPoint.
func ( *GeoPoint) () (*GeoPoint, bool) {
	return , true
}

// DecodeGeoPoint implements binary de-serialization for GeoPointClass.
func ( *bin.Buffer) (GeoPointClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case GeoPointEmptyTypeID:
		// Decoding geoPointEmpty#1117dd5f.
		 := GeoPointEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode GeoPointClass: %w", )
		}
		return &, nil
	case GeoPointTypeID:
		// Decoding geoPoint#b2a2f663.
		 := GeoPoint{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode GeoPointClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode GeoPointClass: %w", bin.NewUnexpectedID())
	}
}

// GeoPoint boxes the GeoPointClass providing a helper.
type GeoPointBox struct {
	GeoPoint GeoPointClass
}

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

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