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

// PhoneConnection represents TL type `phoneConnection#9cc123c7`.
// Identifies an endpoint that can be used to connect to the other user in a phone call
//
// See https://core.telegram.org/constructor/phoneConnection for reference.
type PhoneConnection struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether TCP should be used
	TCP bool
	// Endpoint ID
	ID int64
	// IP address of endpoint
	IP string
	// IPv6 address of endpoint
	Ipv6 string
	// Port ID
	Port int
	// Our peer tag
	PeerTag []byte
}

// PhoneConnectionTypeID is TL type id of PhoneConnection.
const PhoneConnectionTypeID = 0x9cc123c7

// construct implements constructor of PhoneConnectionClass.
func ( PhoneConnection) () PhoneConnectionClass { return & }

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

	_ PhoneConnectionClass = &PhoneConnection{}
)

func ( *PhoneConnection) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.TCP == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.IP == "") {
		return false
	}
	if !(.Ipv6 == "") {
		return false
	}
	if !(.Port == 0) {
		return false
	}
	if !(.PeerTag == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneConnection from given interface.
func ( *PhoneConnection) ( interface {
	() ( bool)
	() ( int64)
	() ( string)
	() ( string)
	() ( int)
	() ( []byte)
}) {
	.TCP = .()
	.ID = .()
	.IP = .()
	.Ipv6 = .()
	.Port = .()
	.PeerTag = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PhoneConnection) () tdp.Type {
	 := tdp.Type{
		Name: "phoneConnection",
		ID:   PhoneConnectionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "TCP",
			SchemaName: "tcp",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "IP",
			SchemaName: "ip",
		},
		{
			Name:       "Ipv6",
			SchemaName: "ipv6",
		},
		{
			Name:       "Port",
			SchemaName: "port",
		},
		{
			Name:       "PeerTag",
			SchemaName: "peer_tag",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PhoneConnection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phoneConnection#9cc123c7 as nil")
	}
	.PutID(PhoneConnectionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhoneConnection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phoneConnection#9cc123c7 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode phoneConnection#9cc123c7: field flags: %w", )
	}
	.PutLong(.ID)
	.PutString(.IP)
	.PutString(.Ipv6)
	.PutInt(.Port)
	.PutBytes(.PeerTag)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PhoneConnection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phoneConnection#9cc123c7 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode phoneConnection#9cc123c7: field flags: %w", )
		}
	}
	.TCP = .Flags.Has(0)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnection#9cc123c7: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnection#9cc123c7: field ip: %w", )
		}
		.IP = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnection#9cc123c7: field ipv6: %w", )
		}
		.Ipv6 = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnection#9cc123c7: field port: %w", )
		}
		.Port = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnection#9cc123c7: field peer_tag: %w", )
		}
		.PeerTag = 
	}
	return nil
}

// SetTCP sets value of TCP conditional field.
func ( *PhoneConnection) ( bool) {
	if  {
		.Flags.Set(0)
		.TCP = true
	} else {
		.Flags.Unset(0)
		.TCP = false
	}
}

// GetTCP returns value of TCP conditional field.
func ( *PhoneConnection) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetID returns value of ID field.
func ( *PhoneConnection) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// GetIP returns value of IP field.
func ( *PhoneConnection) () ( string) {
	if  == nil {
		return
	}
	return .IP
}

// GetIpv6 returns value of Ipv6 field.
func ( *PhoneConnection) () ( string) {
	if  == nil {
		return
	}
	return .Ipv6
}

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

// GetPeerTag returns value of PeerTag field.
func ( *PhoneConnection) () ( []byte) {
	if  == nil {
		return
	}
	return .PeerTag
}

// PhoneConnectionWebrtc represents TL type `phoneConnectionWebrtc#635fe375`.
// WebRTC connection parameters
//
// See https://core.telegram.org/constructor/phoneConnectionWebrtc for reference.
type PhoneConnectionWebrtc struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this is a TURN endpoint
	Turn bool
	// Whether this is a STUN endpoint
	Stun bool
	// Endpoint ID
	ID int64
	// IP address
	IP string
	// IPv6 address
	Ipv6 string
	// Port
	Port int
	// Username
	Username string
	// Password
	Password string
}

// PhoneConnectionWebrtcTypeID is TL type id of PhoneConnectionWebrtc.
const PhoneConnectionWebrtcTypeID = 0x635fe375

// construct implements constructor of PhoneConnectionClass.
func ( PhoneConnectionWebrtc) () PhoneConnectionClass { return & }

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

	_ PhoneConnectionClass = &PhoneConnectionWebrtc{}
)

func ( *PhoneConnectionWebrtc) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Turn == false) {
		return false
	}
	if !(.Stun == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.IP == "") {
		return false
	}
	if !(.Ipv6 == "") {
		return false
	}
	if !(.Port == 0) {
		return false
	}
	if !(.Username == "") {
		return false
	}
	if !(.Password == "") {
		return false
	}

	return true
}

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

// FillFrom fills PhoneConnectionWebrtc from given interface.
func ( *PhoneConnectionWebrtc) ( interface {
	() ( bool)
	() ( bool)
	() ( int64)
	() ( string)
	() ( string)
	() ( int)
	() ( string)
	() ( string)
}) {
	.Turn = .()
	.Stun = .()
	.ID = .()
	.IP = .()
	.Ipv6 = .()
	.Port = .()
	.Username = .()
	.Password = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PhoneConnectionWebrtc) () tdp.Type {
	 := tdp.Type{
		Name: "phoneConnectionWebrtc",
		ID:   PhoneConnectionWebrtcTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Turn",
			SchemaName: "turn",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Stun",
			SchemaName: "stun",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "IP",
			SchemaName: "ip",
		},
		{
			Name:       "Ipv6",
			SchemaName: "ipv6",
		},
		{
			Name:       "Port",
			SchemaName: "port",
		},
		{
			Name:       "Username",
			SchemaName: "username",
		},
		{
			Name:       "Password",
			SchemaName: "password",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PhoneConnectionWebrtc) () {
	if !(.Turn == false) {
		.Flags.Set(0)
	}
	if !(.Stun == false) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *PhoneConnectionWebrtc) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phoneConnectionWebrtc#635fe375 as nil")
	}
	.PutID(PhoneConnectionWebrtcTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhoneConnectionWebrtc) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phoneConnectionWebrtc#635fe375 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode phoneConnectionWebrtc#635fe375: field flags: %w", )
	}
	.PutLong(.ID)
	.PutString(.IP)
	.PutString(.Ipv6)
	.PutInt(.Port)
	.PutString(.Username)
	.PutString(.Password)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PhoneConnectionWebrtc) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phoneConnectionWebrtc#635fe375 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field flags: %w", )
		}
	}
	.Turn = .Flags.Has(0)
	.Stun = .Flags.Has(1)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field ip: %w", )
		}
		.IP = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field ipv6: %w", )
		}
		.Ipv6 = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field port: %w", )
		}
		.Port = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field username: %w", )
		}
		.Username = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode phoneConnectionWebrtc#635fe375: field password: %w", )
		}
		.Password = 
	}
	return nil
}

// SetTurn sets value of Turn conditional field.
func ( *PhoneConnectionWebrtc) ( bool) {
	if  {
		.Flags.Set(0)
		.Turn = true
	} else {
		.Flags.Unset(0)
		.Turn = false
	}
}

// GetTurn returns value of Turn conditional field.
func ( *PhoneConnectionWebrtc) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetStun sets value of Stun conditional field.
func ( *PhoneConnectionWebrtc) ( bool) {
	if  {
		.Flags.Set(1)
		.Stun = true
	} else {
		.Flags.Unset(1)
		.Stun = false
	}
}

// GetStun returns value of Stun conditional field.
func ( *PhoneConnectionWebrtc) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetID returns value of ID field.
func ( *PhoneConnectionWebrtc) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// GetIP returns value of IP field.
func ( *PhoneConnectionWebrtc) () ( string) {
	if  == nil {
		return
	}
	return .IP
}

// GetIpv6 returns value of Ipv6 field.
func ( *PhoneConnectionWebrtc) () ( string) {
	if  == nil {
		return
	}
	return .Ipv6
}

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

// GetUsername returns value of Username field.
func ( *PhoneConnectionWebrtc) () ( string) {
	if  == nil {
		return
	}
	return .Username
}

// GetPassword returns value of Password field.
func ( *PhoneConnectionWebrtc) () ( string) {
	if  == nil {
		return
	}
	return .Password
}

// PhoneConnectionClassName is schema name of PhoneConnectionClass.
const PhoneConnectionClassName = "PhoneConnection"

// PhoneConnectionClass represents PhoneConnection generic type.
//
// See https://core.telegram.org/type/PhoneConnection for reference.
//
// Example:
//
//	g, err := tg.DecodePhoneConnection(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PhoneConnection: // phoneConnection#9cc123c7
//	case *tg.PhoneConnectionWebrtc: // phoneConnectionWebrtc#635fe375
//	default: panic(v)
//	}
type PhoneConnectionClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PhoneConnectionClass

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

	// Endpoint ID
	GetID() (value int64)

	// IP address of endpoint
	GetIP() (value string)

	// IPv6 address of endpoint
	GetIpv6() (value string)

	// Port ID
	GetPort() (value int)
}

// DecodePhoneConnection implements binary de-serialization for PhoneConnectionClass.
func ( *bin.Buffer) (PhoneConnectionClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case PhoneConnectionTypeID:
		// Decoding phoneConnection#9cc123c7.
		 := PhoneConnection{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PhoneConnectionClass: %w", )
		}
		return &, nil
	case PhoneConnectionWebrtcTypeID:
		// Decoding phoneConnectionWebrtc#635fe375.
		 := PhoneConnectionWebrtc{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PhoneConnectionClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode PhoneConnectionClass: %w", bin.NewUnexpectedID())
	}
}

// PhoneConnection boxes the PhoneConnectionClass providing a helper.
type PhoneConnectionBox struct {
	PhoneConnection PhoneConnectionClass
}

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

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