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

// PhoneCallProtocol represents TL type `phoneCallProtocol#fc878fc8`.
// Protocol info for libtgvoip
//
// See https://core.telegram.org/constructor/phoneCallProtocol for reference.
type PhoneCallProtocol struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether to allow P2P connection to the other participant
	UDPP2P bool
	// Whether to allow connection to the other participants through the reflector servers
	UDPReflector bool
	// Minimum layer for remote libtgvoip
	MinLayer int
	// Maximum layer for remote libtgvoip
	MaxLayer int
	// When using phone.requestCall¹ and phone.acceptCall², specify all library versions
	// supported by the client. The server will merge and choose the best library version
	// supported by both peers, returning only the best value in the result of the callee's
	// phone.acceptCall³ and in the phoneCallAccepted⁴ update received by the caller.
	//
	// Links:
	//  1) https://core.telegram.org/method/phone.requestCall
	//  2) https://core.telegram.org/method/phone.acceptCall
	//  3) https://core.telegram.org/method/phone.acceptCall
	//  4) https://core.telegram.org/constructor/phoneCallAccepted
	LibraryVersions []string
}

// PhoneCallProtocolTypeID is TL type id of PhoneCallProtocol.
const PhoneCallProtocolTypeID = 0xfc878fc8

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

func ( *PhoneCallProtocol) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.UDPP2P == false) {
		return false
	}
	if !(.UDPReflector == false) {
		return false
	}
	if !(.MinLayer == 0) {
		return false
	}
	if !(.MaxLayer == 0) {
		return false
	}
	if !(.LibraryVersions == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneCallProtocol from given interface.
func ( *PhoneCallProtocol) ( interface {
	() ( bool)
	() ( bool)
	() ( int)
	() ( int)
	() ( []string)
}) {
	.UDPP2P = .()
	.UDPReflector = .()
	.MinLayer = .()
	.MaxLayer = .()
	.LibraryVersions = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PhoneCallProtocol) () tdp.Type {
	 := tdp.Type{
		Name: "phoneCallProtocol",
		ID:   PhoneCallProtocolTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UDPP2P",
			SchemaName: "udp_p2p",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "UDPReflector",
			SchemaName: "udp_reflector",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "MinLayer",
			SchemaName: "min_layer",
		},
		{
			Name:       "MaxLayer",
			SchemaName: "max_layer",
		},
		{
			Name:       "LibraryVersions",
			SchemaName: "library_versions",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PhoneCallProtocol) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phoneCallProtocol#fc878fc8 as nil")
	}
	.PutID(PhoneCallProtocolTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhoneCallProtocol) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phoneCallProtocol#fc878fc8 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode phoneCallProtocol#fc878fc8: field flags: %w", )
	}
	.PutInt(.MinLayer)
	.PutInt(.MaxLayer)
	.PutVectorHeader(len(.LibraryVersions))
	for ,  := range .LibraryVersions {
		.PutString()
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PhoneCallProtocol) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phoneCallProtocol#fc878fc8 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode phoneCallProtocol#fc878fc8: field flags: %w", )
		}
	}
	.UDPP2P = .Flags.Has(0)
	.UDPReflector = .Flags.Has(1)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode phoneCallProtocol#fc878fc8: field min_layer: %w", )
		}
		.MinLayer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode phoneCallProtocol#fc878fc8: field max_layer: %w", )
		}
		.MaxLayer = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode phoneCallProtocol#fc878fc8: field library_versions: %w", )
		}

		if  > 0 {
			.LibraryVersions = make([]string, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .String()
			if  != nil {
				return fmt.Errorf("unable to decode phoneCallProtocol#fc878fc8: field library_versions: %w", )
			}
			.LibraryVersions = append(.LibraryVersions, )
		}
	}
	return nil
}

// SetUDPP2P sets value of UDPP2P conditional field.
func ( *PhoneCallProtocol) ( bool) {
	if  {
		.Flags.Set(0)
		.UDPP2P = true
	} else {
		.Flags.Unset(0)
		.UDPP2P = false
	}
}

// GetUDPP2P returns value of UDPP2P conditional field.
func ( *PhoneCallProtocol) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetUDPReflector sets value of UDPReflector conditional field.
func ( *PhoneCallProtocol) ( bool) {
	if  {
		.Flags.Set(1)
		.UDPReflector = true
	} else {
		.Flags.Unset(1)
		.UDPReflector = false
	}
}

// GetUDPReflector returns value of UDPReflector conditional field.
func ( *PhoneCallProtocol) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetMinLayer returns value of MinLayer field.
func ( *PhoneCallProtocol) () ( int) {
	if  == nil {
		return
	}
	return .MinLayer
}

// GetMaxLayer returns value of MaxLayer field.
func ( *PhoneCallProtocol) () ( int) {
	if  == nil {
		return
	}
	return .MaxLayer
}

// GetLibraryVersions returns value of LibraryVersions field.
func ( *PhoneCallProtocol) () ( []string) {
	if  == nil {
		return
	}
	return .LibraryVersions
}