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

// IPPort represents TL type `ipPort#d433ad73`.
//
// See https://core.telegram.org/constructor/ipPort for reference.
type IPPort struct {
	// Ipv4 field of IPPort.
	Ipv4 int
	// Port field of IPPort.
	Port int
}

// IPPortTypeID is TL type id of IPPort.
const IPPortTypeID = 0xd433ad73

// construct implements constructor of IPPortClass.
func ( IPPort) () IPPortClass { return & }

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

	_ IPPortClass = &IPPort{}
)

func ( *IPPort) () bool {
	if  == nil {
		return true
	}
	if !(.Ipv4 == 0) {
		return false
	}
	if !(.Port == 0) {
		return false
	}

	return true
}

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

// FillFrom fills IPPort from given interface.
func ( *IPPort) ( interface {
	() ( int)
	() ( int)
}) {
	.Ipv4 = .()
	.Port = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *IPPort) () tdp.Type {
	 := tdp.Type{
		Name: "ipPort",
		ID:   IPPortTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Ipv4",
			SchemaName: "ipv4",
		},
		{
			Name:       "Port",
			SchemaName: "port",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *IPPort) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode ipPort#d433ad73 as nil")
	}
	.PutID(IPPortTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *IPPort) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode ipPort#d433ad73 as nil")
	}
	.PutInt(.Ipv4)
	.PutInt(.Port)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *IPPort) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode ipPort#d433ad73 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode ipPort#d433ad73: field ipv4: %w", )
		}
		.Ipv4 = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode ipPort#d433ad73: field port: %w", )
		}
		.Port = 
	}
	return nil
}

// GetIpv4 returns value of Ipv4 field.
func ( *IPPort) () ( int) {
	if  == nil {
		return
	}
	return .Ipv4
}

// GetPort returns value of Port field.
func ( *IPPort) () ( int) {
	if  == nil {
		return
	}
	return .Port
}

// IPPortSecret represents TL type `ipPortSecret#37982646`.
//
// See https://core.telegram.org/constructor/ipPortSecret for reference.
type IPPortSecret struct {
	// Ipv4 field of IPPortSecret.
	Ipv4 int
	// Port field of IPPortSecret.
	Port int
	// Secret field of IPPortSecret.
	Secret []byte
}

// IPPortSecretTypeID is TL type id of IPPortSecret.
const IPPortSecretTypeID = 0x37982646

// construct implements constructor of IPPortClass.
func ( IPPortSecret) () IPPortClass { return & }

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

	_ IPPortClass = &IPPortSecret{}
)

func ( *IPPortSecret) () bool {
	if  == nil {
		return true
	}
	if !(.Ipv4 == 0) {
		return false
	}
	if !(.Port == 0) {
		return false
	}
	if !(.Secret == nil) {
		return false
	}

	return true
}

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

// FillFrom fills IPPortSecret from given interface.
func ( *IPPortSecret) ( interface {
	() ( int)
	() ( int)
	() ( []byte)
}) {
	.Ipv4 = .()
	.Port = .()
	.Secret = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *IPPortSecret) () tdp.Type {
	 := tdp.Type{
		Name: "ipPortSecret",
		ID:   IPPortSecretTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Ipv4",
			SchemaName: "ipv4",
		},
		{
			Name:       "Port",
			SchemaName: "port",
		},
		{
			Name:       "Secret",
			SchemaName: "secret",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *IPPortSecret) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode ipPortSecret#37982646 as nil")
	}
	.PutID(IPPortSecretTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *IPPortSecret) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode ipPortSecret#37982646 as nil")
	}
	.PutInt(.Ipv4)
	.PutInt(.Port)
	.PutBytes(.Secret)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *IPPortSecret) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode ipPortSecret#37982646 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode ipPortSecret#37982646: field ipv4: %w", )
		}
		.Ipv4 = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode ipPortSecret#37982646: field port: %w", )
		}
		.Port = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode ipPortSecret#37982646: field secret: %w", )
		}
		.Secret = 
	}
	return nil
}

// GetIpv4 returns value of Ipv4 field.
func ( *IPPortSecret) () ( int) {
	if  == nil {
		return
	}
	return .Ipv4
}

// GetPort returns value of Port field.
func ( *IPPortSecret) () ( int) {
	if  == nil {
		return
	}
	return .Port
}

// GetSecret returns value of Secret field.
func ( *IPPortSecret) () ( []byte) {
	if  == nil {
		return
	}
	return .Secret
}

// IPPortClassName is schema name of IPPortClass.
const IPPortClassName = "IpPort"

// IPPortClass represents IpPort generic type.
//
// See https://core.telegram.org/type/IpPort for reference.
//
// Example:
//
//	g, err := tg.DecodeIPPort(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.IPPort: // ipPort#d433ad73
//	case *tg.IPPortSecret: // ipPortSecret#37982646
//	default: panic(v)
//	}
type IPPortClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() IPPortClass

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

	// Ipv4 field of IPPort.
	GetIpv4() (value int)

	// Port field of IPPort.
	GetPort() (value int)
}

// DecodeIPPort implements binary de-serialization for IPPortClass.
func ( *bin.Buffer) (IPPortClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case IPPortTypeID:
		// Decoding ipPort#d433ad73.
		 := IPPort{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode IPPortClass: %w", )
		}
		return &, nil
	case IPPortSecretTypeID:
		// Decoding ipPortSecret#37982646.
		 := IPPortSecret{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode IPPortClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode IPPortClass: %w", bin.NewUnexpectedID())
	}
}

// IPPort boxes the IPPortClass providing a helper.
type IPPortBox struct {
	IpPort IPPortClass
}

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

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