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

// Authorization represents TL type `authorization#ad01d61d`.
// Logged-in session
//
// See https://core.telegram.org/constructor/authorization for reference.
type Authorization struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this is the current session
	Current bool
	// Whether the session is from an official app
	OfficialApp bool
	// Whether the session is still waiting for a 2FA password
	PasswordPending bool
	// Whether this session will accept encrypted chats
	EncryptedRequestsDisabled bool
	// Whether this session will accept phone calls
	CallRequestsDisabled bool
	// Whether the session is unconfirmed, see here »¹ for more info.
	//
	// Links:
	//  1) https://core.telegram.org/api/auth#confirming-login
	Unconfirmed bool
	// Identifier
	Hash int64
	// Device model
	DeviceModel string
	// Platform
	Platform string
	// System version
	SystemVersion string
	// API ID¹
	//
	// Links:
	//  1) https://core.telegram.org/api/obtaining_api_id
	APIID int
	// App name
	AppName string
	// App version
	AppVersion string
	// When was the session created
	DateCreated int
	// When was the session last active
	DateActive int
	// Last known IP
	IP string
	// Country determined from IP
	Country string
	// Region determined from IP
	Region string
}

// AuthorizationTypeID is TL type id of Authorization.
const AuthorizationTypeID = 0xad01d61d

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

func ( *Authorization) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Current == false) {
		return false
	}
	if !(.OfficialApp == false) {
		return false
	}
	if !(.PasswordPending == false) {
		return false
	}
	if !(.EncryptedRequestsDisabled == false) {
		return false
	}
	if !(.CallRequestsDisabled == false) {
		return false
	}
	if !(.Unconfirmed == false) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}
	if !(.DeviceModel == "") {
		return false
	}
	if !(.Platform == "") {
		return false
	}
	if !(.SystemVersion == "") {
		return false
	}
	if !(.APIID == 0) {
		return false
	}
	if !(.AppName == "") {
		return false
	}
	if !(.AppVersion == "") {
		return false
	}
	if !(.DateCreated == 0) {
		return false
	}
	if !(.DateActive == 0) {
		return false
	}
	if !(.IP == "") {
		return false
	}
	if !(.Country == "") {
		return false
	}
	if !(.Region == "") {
		return false
	}

	return true
}

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

// FillFrom fills Authorization from given interface.
func ( *Authorization) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int64)
	() ( string)
	() ( string)
	() ( string)
	() ( int)
	() ( string)
	() ( string)
	() ( int)
	() ( int)
	() ( string)
	() ( string)
	() ( string)
}) {
	.Current = .()
	.OfficialApp = .()
	.PasswordPending = .()
	.EncryptedRequestsDisabled = .()
	.CallRequestsDisabled = .()
	.Unconfirmed = .()
	.Hash = .()
	.DeviceModel = .()
	.Platform = .()
	.SystemVersion = .()
	.APIID = .()
	.AppName = .()
	.AppVersion = .()
	.DateCreated = .()
	.DateActive = .()
	.IP = .()
	.Country = .()
	.Region = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *Authorization) () tdp.Type {
	 := tdp.Type{
		Name: "authorization",
		ID:   AuthorizationTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Current",
			SchemaName: "current",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "OfficialApp",
			SchemaName: "official_app",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PasswordPending",
			SchemaName: "password_pending",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "EncryptedRequestsDisabled",
			SchemaName: "encrypted_requests_disabled",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "CallRequestsDisabled",
			SchemaName: "call_requests_disabled",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Unconfirmed",
			SchemaName: "unconfirmed",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
		{
			Name:       "DeviceModel",
			SchemaName: "device_model",
		},
		{
			Name:       "Platform",
			SchemaName: "platform",
		},
		{
			Name:       "SystemVersion",
			SchemaName: "system_version",
		},
		{
			Name:       "APIID",
			SchemaName: "api_id",
		},
		{
			Name:       "AppName",
			SchemaName: "app_name",
		},
		{
			Name:       "AppVersion",
			SchemaName: "app_version",
		},
		{
			Name:       "DateCreated",
			SchemaName: "date_created",
		},
		{
			Name:       "DateActive",
			SchemaName: "date_active",
		},
		{
			Name:       "IP",
			SchemaName: "ip",
		},
		{
			Name:       "Country",
			SchemaName: "country",
		},
		{
			Name:       "Region",
			SchemaName: "region",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Authorization) () {
	if !(.Current == false) {
		.Flags.Set(0)
	}
	if !(.OfficialApp == false) {
		.Flags.Set(1)
	}
	if !(.PasswordPending == false) {
		.Flags.Set(2)
	}
	if !(.EncryptedRequestsDisabled == false) {
		.Flags.Set(3)
	}
	if !(.CallRequestsDisabled == false) {
		.Flags.Set(4)
	}
	if !(.Unconfirmed == false) {
		.Flags.Set(5)
	}
}

// Encode implements bin.Encoder.
func ( *Authorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode authorization#ad01d61d as nil")
	}
	.PutID(AuthorizationTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Authorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode authorization#ad01d61d as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode authorization#ad01d61d: field flags: %w", )
	}
	.PutLong(.Hash)
	.PutString(.DeviceModel)
	.PutString(.Platform)
	.PutString(.SystemVersion)
	.PutInt(.APIID)
	.PutString(.AppName)
	.PutString(.AppVersion)
	.PutInt(.DateCreated)
	.PutInt(.DateActive)
	.PutString(.IP)
	.PutString(.Country)
	.PutString(.Region)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *Authorization) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode authorization#ad01d61d to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field flags: %w", )
		}
	}
	.Current = .Flags.Has(0)
	.OfficialApp = .Flags.Has(1)
	.PasswordPending = .Flags.Has(2)
	.EncryptedRequestsDisabled = .Flags.Has(3)
	.CallRequestsDisabled = .Flags.Has(4)
	.Unconfirmed = .Flags.Has(5)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field hash: %w", )
		}
		.Hash = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field device_model: %w", )
		}
		.DeviceModel = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field platform: %w", )
		}
		.Platform = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field system_version: %w", )
		}
		.SystemVersion = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field api_id: %w", )
		}
		.APIID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field app_name: %w", )
		}
		.AppName = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field app_version: %w", )
		}
		.AppVersion = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field date_created: %w", )
		}
		.DateCreated = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field date_active: %w", )
		}
		.DateActive = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field ip: %w", )
		}
		.IP = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field country: %w", )
		}
		.Country = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode authorization#ad01d61d: field region: %w", )
		}
		.Region = 
	}
	return nil
}

// SetCurrent sets value of Current conditional field.
func ( *Authorization) ( bool) {
	if  {
		.Flags.Set(0)
		.Current = true
	} else {
		.Flags.Unset(0)
		.Current = false
	}
}

// GetCurrent returns value of Current conditional field.
func ( *Authorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetOfficialApp sets value of OfficialApp conditional field.
func ( *Authorization) ( bool) {
	if  {
		.Flags.Set(1)
		.OfficialApp = true
	} else {
		.Flags.Unset(1)
		.OfficialApp = false
	}
}

// GetOfficialApp returns value of OfficialApp conditional field.
func ( *Authorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetPasswordPending sets value of PasswordPending conditional field.
func ( *Authorization) ( bool) {
	if  {
		.Flags.Set(2)
		.PasswordPending = true
	} else {
		.Flags.Unset(2)
		.PasswordPending = false
	}
}

// GetPasswordPending returns value of PasswordPending conditional field.
func ( *Authorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetEncryptedRequestsDisabled sets value of EncryptedRequestsDisabled conditional field.
func ( *Authorization) ( bool) {
	if  {
		.Flags.Set(3)
		.EncryptedRequestsDisabled = true
	} else {
		.Flags.Unset(3)
		.EncryptedRequestsDisabled = false
	}
}

// GetEncryptedRequestsDisabled returns value of EncryptedRequestsDisabled conditional field.
func ( *Authorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetCallRequestsDisabled sets value of CallRequestsDisabled conditional field.
func ( *Authorization) ( bool) {
	if  {
		.Flags.Set(4)
		.CallRequestsDisabled = true
	} else {
		.Flags.Unset(4)
		.CallRequestsDisabled = false
	}
}

// GetCallRequestsDisabled returns value of CallRequestsDisabled conditional field.
func ( *Authorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetUnconfirmed sets value of Unconfirmed conditional field.
func ( *Authorization) ( bool) {
	if  {
		.Flags.Set(5)
		.Unconfirmed = true
	} else {
		.Flags.Unset(5)
		.Unconfirmed = false
	}
}

// GetUnconfirmed returns value of Unconfirmed conditional field.
func ( *Authorization) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// GetHash returns value of Hash field.
func ( *Authorization) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}

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

// GetPlatform returns value of Platform field.
func ( *Authorization) () ( string) {
	if  == nil {
		return
	}
	return .Platform
}

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

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

// GetAppName returns value of AppName field.
func ( *Authorization) () ( string) {
	if  == nil {
		return
	}
	return .AppName
}

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

// GetDateCreated returns value of DateCreated field.
func ( *Authorization) () ( int) {
	if  == nil {
		return
	}
	return .DateCreated
}

// GetDateActive returns value of DateActive field.
func ( *Authorization) () ( int) {
	if  == nil {
		return
	}
	return .DateActive
}

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

// GetCountry returns value of Country field.
func ( *Authorization) () ( string) {
	if  == nil {
		return
	}
	return .Country
}

// GetRegion returns value of Region field.
func ( *Authorization) () ( string) {
	if  == nil {
		return
	}
	return .Region
}