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

// ChannelLocationEmpty represents TL type `channelLocationEmpty#bfb5ad8b`.
// No location (normal supergroup)
//
// See https://core.telegram.org/constructor/channelLocationEmpty for reference.
type ChannelLocationEmpty struct {
}

// ChannelLocationEmptyTypeID is TL type id of ChannelLocationEmpty.
const ChannelLocationEmptyTypeID = 0xbfb5ad8b

// construct implements constructor of ChannelLocationClass.
func ( ChannelLocationEmpty) () ChannelLocationClass { return & }

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

	_ ChannelLocationClass = &ChannelLocationEmpty{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func ( *ChannelLocationEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channelLocationEmpty#bfb5ad8b as nil")
	}
	.PutID(ChannelLocationEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChannelLocationEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channelLocationEmpty#bfb5ad8b as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ChannelLocationEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channelLocationEmpty#bfb5ad8b to nil")
	}
	return nil
}

// ChannelLocation represents TL type `channelLocation#209b82db`.
// Geographical location of supergroup (geogroups)
//
// See https://core.telegram.org/constructor/channelLocation for reference.
type ChannelLocation struct {
	// Geographical location of supergroup
	GeoPoint GeoPointClass
	// Textual description of the address
	Address string
}

// ChannelLocationTypeID is TL type id of ChannelLocation.
const ChannelLocationTypeID = 0x209b82db

// construct implements constructor of ChannelLocationClass.
func ( ChannelLocation) () ChannelLocationClass { return & }

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

	_ ChannelLocationClass = &ChannelLocation{}
)

func ( *ChannelLocation) () bool {
	if  == nil {
		return true
	}
	if !(.GeoPoint == nil) {
		return false
	}
	if !(.Address == "") {
		return false
	}

	return true
}

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

// FillFrom fills ChannelLocation from given interface.
func ( *ChannelLocation) ( interface {
	() ( GeoPointClass)
	() ( string)
}) {
	.GeoPoint = .()
	.Address = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ChannelLocation) () tdp.Type {
	 := tdp.Type{
		Name: "channelLocation",
		ID:   ChannelLocationTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "GeoPoint",
			SchemaName: "geo_point",
		},
		{
			Name:       "Address",
			SchemaName: "address",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ChannelLocation) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channelLocation#209b82db as nil")
	}
	.PutID(ChannelLocationTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChannelLocation) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channelLocation#209b82db as nil")
	}
	if .GeoPoint == nil {
		return fmt.Errorf("unable to encode channelLocation#209b82db: field geo_point is nil")
	}
	if  := .GeoPoint.Encode();  != nil {
		return fmt.Errorf("unable to encode channelLocation#209b82db: field geo_point: %w", )
	}
	.PutString(.Address)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ChannelLocation) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channelLocation#209b82db to nil")
	}
	{
		,  := DecodeGeoPoint()
		if  != nil {
			return fmt.Errorf("unable to decode channelLocation#209b82db: field geo_point: %w", )
		}
		.GeoPoint = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode channelLocation#209b82db: field address: %w", )
		}
		.Address = 
	}
	return nil
}

// GetGeoPoint returns value of GeoPoint field.
func ( *ChannelLocation) () ( GeoPointClass) {
	if  == nil {
		return
	}
	return .GeoPoint
}

// GetAddress returns value of Address field.
func ( *ChannelLocation) () ( string) {
	if  == nil {
		return
	}
	return .Address
}

// ChannelLocationClassName is schema name of ChannelLocationClass.
const ChannelLocationClassName = "ChannelLocation"

// ChannelLocationClass represents ChannelLocation generic type.
//
// See https://core.telegram.org/type/ChannelLocation for reference.
//
// Example:
//
//	g, err := tg.DecodeChannelLocation(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ChannelLocationEmpty: // channelLocationEmpty#bfb5ad8b
//	case *tg.ChannelLocation: // channelLocation#209b82db
//	default: panic(v)
//	}
type ChannelLocationClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ChannelLocationClass

	// 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 ChannelLocationClass to ChannelLocation.
	AsNotEmpty() (*ChannelLocation, bool)
}

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

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

// DecodeChannelLocation implements binary de-serialization for ChannelLocationClass.
func ( *bin.Buffer) (ChannelLocationClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ChannelLocationEmptyTypeID:
		// Decoding channelLocationEmpty#bfb5ad8b.
		 := ChannelLocationEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChannelLocationClass: %w", )
		}
		return &, nil
	case ChannelLocationTypeID:
		// Decoding channelLocation#209b82db.
		 := ChannelLocation{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChannelLocationClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ChannelLocationClass: %w", bin.NewUnexpectedID())
	}
}

// ChannelLocation boxes the ChannelLocationClass providing a helper.
type ChannelLocationBox struct {
	ChannelLocation ChannelLocationClass
}

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

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