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

// InitConnectionRequest represents TL type `initConnection#c1cd5ea9`.
// Initialize connection
//
// See https://core.telegram.org/constructor/initConnection for reference.
type InitConnectionRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Application identifier (see. App configurationĀ¹)
	//
	// Links:
	//  1) https://core.telegram.org/myapp
	APIID int
	// Device model
	DeviceModel string
	// Operation system version
	SystemVersion string
	// Application version
	AppVersion string
	// Code for the language used on the device's OS, ISO 639-1 standard
	SystemLangCode string
	// Language pack to use
	LangPack string
	// Code for the language used on the client, ISO 639-1 standard
	LangCode string
	// Info about an MTProto proxy
	//
	// Use SetProxy and GetProxy helpers.
	Proxy InputClientProxy
	// Additional initConnection parameters. For now, only the tz_offset field is supported,
	// for specifying timezone offset in seconds.
	//
	// Use SetParams and GetParams helpers.
	Params JSONValueClass
	// The query itself
	Query bin.Object
}

// InitConnectionRequestTypeID is TL type id of InitConnectionRequest.
const InitConnectionRequestTypeID = 0xc1cd5ea9

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

func ( *InitConnectionRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.APIID == 0) {
		return false
	}
	if !(.DeviceModel == "") {
		return false
	}
	if !(.SystemVersion == "") {
		return false
	}
	if !(.AppVersion == "") {
		return false
	}
	if !(.SystemLangCode == "") {
		return false
	}
	if !(.LangPack == "") {
		return false
	}
	if !(.LangCode == "") {
		return false
	}
	if !(.Proxy.Zero()) {
		return false
	}
	if !(.Params == nil) {
		return false
	}
	if !(.Query == nil) {
		return false
	}

	return true
}

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

// FillFrom fills InitConnectionRequest from given interface.
func ( *InitConnectionRequest) ( interface {
	() ( int)
	() ( string)
	() ( string)
	() ( string)
	() ( string)
	() ( string)
	() ( string)
	() ( InputClientProxy,  bool)
	() ( JSONValueClass,  bool)
	() ( bin.Object)
}) {
	.APIID = .()
	.DeviceModel = .()
	.SystemVersion = .()
	.AppVersion = .()
	.SystemLangCode = .()
	.LangPack = .()
	.LangCode = .()
	if ,  := .();  {
		.Proxy = 
	}

	if ,  := .();  {
		.Params = 
	}

	.Query = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *InitConnectionRequest) () tdp.Type {
	 := tdp.Type{
		Name: "initConnection",
		ID:   InitConnectionRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "APIID",
			SchemaName: "api_id",
		},
		{
			Name:       "DeviceModel",
			SchemaName: "device_model",
		},
		{
			Name:       "SystemVersion",
			SchemaName: "system_version",
		},
		{
			Name:       "AppVersion",
			SchemaName: "app_version",
		},
		{
			Name:       "SystemLangCode",
			SchemaName: "system_lang_code",
		},
		{
			Name:       "LangPack",
			SchemaName: "lang_pack",
		},
		{
			Name:       "LangCode",
			SchemaName: "lang_code",
		},
		{
			Name:       "Proxy",
			SchemaName: "proxy",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Params",
			SchemaName: "params",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Query",
			SchemaName: "query",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *InitConnectionRequest) () {
	if !(.Proxy.Zero()) {
		.Flags.Set(0)
	}
	if !(.Params == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *InitConnectionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode initConnection#c1cd5ea9 as nil")
	}
	.PutID(InitConnectionRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *InitConnectionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode initConnection#c1cd5ea9 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode initConnection#c1cd5ea9: field flags: %w", )
	}
	.PutInt(.APIID)
	.PutString(.DeviceModel)
	.PutString(.SystemVersion)
	.PutString(.AppVersion)
	.PutString(.SystemLangCode)
	.PutString(.LangPack)
	.PutString(.LangCode)
	if .Flags.Has(0) {
		if  := .Proxy.Encode();  != nil {
			return fmt.Errorf("unable to encode initConnection#c1cd5ea9: field proxy: %w", )
		}
	}
	if .Flags.Has(1) {
		if .Params == nil {
			return fmt.Errorf("unable to encode initConnection#c1cd5ea9: field params is nil")
		}
		if  := .Params.Encode();  != nil {
			return fmt.Errorf("unable to encode initConnection#c1cd5ea9: field params: %w", )
		}
	}
	if  := .Query.Encode();  != nil {
		return fmt.Errorf("unable to encode initConnection#c1cd5ea9: field query: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *InitConnectionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode initConnection#c1cd5ea9 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field api_id: %w", )
		}
		.APIID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field device_model: %w", )
		}
		.DeviceModel = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field system_version: %w", )
		}
		.SystemVersion = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field app_version: %w", )
		}
		.AppVersion = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field system_lang_code: %w", )
		}
		.SystemLangCode = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field lang_pack: %w", )
		}
		.LangPack = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field lang_code: %w", )
		}
		.LangCode = 
	}
	if .Flags.Has(0) {
		if  := .Proxy.Decode();  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field proxy: %w", )
		}
	}
	if .Flags.Has(1) {
		,  := DecodeJSONValue()
		if  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field params: %w", )
		}
		.Params = 
	}
	{
		if  := .Query.Decode();  != nil {
			return fmt.Errorf("unable to decode initConnection#c1cd5ea9: field query: %w", )
		}
	}
	return nil
}

// GetAPIID returns value of APIID field.
func ( *InitConnectionRequest) () ( int) {
	if  == nil {
		return
	}
	return .APIID
}

// GetDeviceModel returns value of DeviceModel field.
func ( *InitConnectionRequest) () ( string) {
	if  == nil {
		return
	}
	return .DeviceModel
}

// GetSystemVersion returns value of SystemVersion field.
func ( *InitConnectionRequest) () ( string) {
	if  == nil {
		return
	}
	return .SystemVersion
}

// GetAppVersion returns value of AppVersion field.
func ( *InitConnectionRequest) () ( string) {
	if  == nil {
		return
	}
	return .AppVersion
}

// GetSystemLangCode returns value of SystemLangCode field.
func ( *InitConnectionRequest) () ( string) {
	if  == nil {
		return
	}
	return .SystemLangCode
}

// GetLangPack returns value of LangPack field.
func ( *InitConnectionRequest) () ( string) {
	if  == nil {
		return
	}
	return .LangPack
}

// GetLangCode returns value of LangCode field.
func ( *InitConnectionRequest) () ( string) {
	if  == nil {
		return
	}
	return .LangCode
}

// SetProxy sets value of Proxy conditional field.
func ( *InitConnectionRequest) ( InputClientProxy) {
	.Flags.Set(0)
	.Proxy = 
}

// GetProxy returns value of Proxy conditional field and
// boolean which is true if field was set.
func ( *InitConnectionRequest) () ( InputClientProxy,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Proxy, true
}

// SetParams sets value of Params conditional field.
func ( *InitConnectionRequest) ( JSONValueClass) {
	.Flags.Set(1)
	.Params = 
}

// GetParams returns value of Params conditional field and
// boolean which is true if field was set.
func ( *InitConnectionRequest) () ( JSONValueClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Params, true
}

// GetQuery returns value of Query field.
func ( *InitConnectionRequest) () ( bin.Object) {
	if  == nil {
		return
	}
	return .Query
}