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

// DCOption represents TL type `dcOption#18b7a10d`.
// Data center
//
// See https://core.telegram.org/constructor/dcOption for reference.
type DCOption struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the specified IP is an IPv6 address
	Ipv6 bool
	// Whether this DC should only be used to download or upload files¹
	//
	// Links:
	//  1) https://core.telegram.org/api/files
	MediaOnly bool
	// Whether this DC only supports connection with transport obfuscation¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation
	TCPObfuscatedOnly bool
	// Whether this is a CDN DC¹.
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	CDN bool
	// If set, this IP should be used when connecting through a proxy
	Static bool
	// If set, clients must connect using only the specified port, without trying any other
	// port.
	ThisPortOnly bool
	// DC ID
	ID int
	// IP address of DC
	IPAddress string
	// Port
	Port int
	// If the tcpo_only flag is set, specifies the secret to use when connecting using
	// transport obfuscation¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation
	//
	// Use SetSecret and GetSecret helpers.
	Secret []byte
}

// DCOptionTypeID is TL type id of DCOption.
const DCOptionTypeID = 0x18b7a10d

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

func ( *DCOption) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Ipv6 == false) {
		return false
	}
	if !(.MediaOnly == false) {
		return false
	}
	if !(.TCPObfuscatedOnly == false) {
		return false
	}
	if !(.CDN == false) {
		return false
	}
	if !(.Static == false) {
		return false
	}
	if !(.ThisPortOnly == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.IPAddress == "") {
		return false
	}
	if !(.Port == 0) {
		return false
	}
	if !(.Secret == nil) {
		return false
	}

	return true
}

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

// FillFrom fills DCOption from given interface.
func ( *DCOption) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int)
	() ( string)
	() ( int)
	() ( []byte,  bool)
}) {
	.Ipv6 = .()
	.MediaOnly = .()
	.TCPObfuscatedOnly = .()
	.CDN = .()
	.Static = .()
	.ThisPortOnly = .()
	.ID = .()
	.IPAddress = .()
	.Port = .()
	if ,  := .();  {
		.Secret = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *DCOption) () tdp.Type {
	 := tdp.Type{
		Name: "dcOption",
		ID:   DCOptionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Ipv6",
			SchemaName: "ipv6",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "MediaOnly",
			SchemaName: "media_only",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "TCPObfuscatedOnly",
			SchemaName: "tcpo_only",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "CDN",
			SchemaName: "cdn",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Static",
			SchemaName: "static",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ThisPortOnly",
			SchemaName: "this_port_only",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "IPAddress",
			SchemaName: "ip_address",
		},
		{
			Name:       "Port",
			SchemaName: "port",
		},
		{
			Name:       "Secret",
			SchemaName: "secret",
			Null:       !.Flags.Has(10),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *DCOption) () {
	if !(.Ipv6 == false) {
		.Flags.Set(0)
	}
	if !(.MediaOnly == false) {
		.Flags.Set(1)
	}
	if !(.TCPObfuscatedOnly == false) {
		.Flags.Set(2)
	}
	if !(.CDN == false) {
		.Flags.Set(3)
	}
	if !(.Static == false) {
		.Flags.Set(4)
	}
	if !(.ThisPortOnly == false) {
		.Flags.Set(5)
	}
	if !(.Secret == nil) {
		.Flags.Set(10)
	}
}

// Encode implements bin.Encoder.
func ( *DCOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode dcOption#18b7a10d as nil")
	}
	.PutID(DCOptionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *DCOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode dcOption#18b7a10d as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode dcOption#18b7a10d: field flags: %w", )
	}
	.PutInt(.ID)
	.PutString(.IPAddress)
	.PutInt(.Port)
	if .Flags.Has(10) {
		.PutBytes(.Secret)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *DCOption) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode dcOption#18b7a10d to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode dcOption#18b7a10d: field flags: %w", )
		}
	}
	.Ipv6 = .Flags.Has(0)
	.MediaOnly = .Flags.Has(1)
	.TCPObfuscatedOnly = .Flags.Has(2)
	.CDN = .Flags.Has(3)
	.Static = .Flags.Has(4)
	.ThisPortOnly = .Flags.Has(5)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode dcOption#18b7a10d: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode dcOption#18b7a10d: field ip_address: %w", )
		}
		.IPAddress = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode dcOption#18b7a10d: field port: %w", )
		}
		.Port = 
	}
	if .Flags.Has(10) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode dcOption#18b7a10d: field secret: %w", )
		}
		.Secret = 
	}
	return nil
}

// SetIpv6 sets value of Ipv6 conditional field.
func ( *DCOption) ( bool) {
	if  {
		.Flags.Set(0)
		.Ipv6 = true
	} else {
		.Flags.Unset(0)
		.Ipv6 = false
	}
}

// GetIpv6 returns value of Ipv6 conditional field.
func ( *DCOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetMediaOnly sets value of MediaOnly conditional field.
func ( *DCOption) ( bool) {
	if  {
		.Flags.Set(1)
		.MediaOnly = true
	} else {
		.Flags.Unset(1)
		.MediaOnly = false
	}
}

// GetMediaOnly returns value of MediaOnly conditional field.
func ( *DCOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetTCPObfuscatedOnly sets value of TCPObfuscatedOnly conditional field.
func ( *DCOption) ( bool) {
	if  {
		.Flags.Set(2)
		.TCPObfuscatedOnly = true
	} else {
		.Flags.Unset(2)
		.TCPObfuscatedOnly = false
	}
}

// GetTCPObfuscatedOnly returns value of TCPObfuscatedOnly conditional field.
func ( *DCOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetCDN sets value of CDN conditional field.
func ( *DCOption) ( bool) {
	if  {
		.Flags.Set(3)
		.CDN = true
	} else {
		.Flags.Unset(3)
		.CDN = false
	}
}

// GetCDN returns value of CDN conditional field.
func ( *DCOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetStatic sets value of Static conditional field.
func ( *DCOption) ( bool) {
	if  {
		.Flags.Set(4)
		.Static = true
	} else {
		.Flags.Unset(4)
		.Static = false
	}
}

// GetStatic returns value of Static conditional field.
func ( *DCOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetThisPortOnly sets value of ThisPortOnly conditional field.
func ( *DCOption) ( bool) {
	if  {
		.Flags.Set(5)
		.ThisPortOnly = true
	} else {
		.Flags.Unset(5)
		.ThisPortOnly = false
	}
}

// GetThisPortOnly returns value of ThisPortOnly conditional field.
func ( *DCOption) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

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

// GetIPAddress returns value of IPAddress field.
func ( *DCOption) () ( string) {
	if  == nil {
		return
	}
	return .IPAddress
}

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

// SetSecret sets value of Secret conditional field.
func ( *DCOption) ( []byte) {
	.Flags.Set(10)
	.Secret = 
}

// GetSecret returns value of Secret conditional field and
// boolean which is true if field was set.
func ( *DCOption) () ( []byte,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(10) {
		return , false
	}
	return .Secret, true
}