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

// AuthSignInRequest represents TL type `auth.signIn#8d52a951`.
// Signs in a user with a validated phone number.
//
// See https://core.telegram.org/method/auth.signIn for reference.
type AuthSignInRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Phone number in the international format
	PhoneNumber string
	// SMS-message ID, obtained from auth.sendCode¹
	//
	// Links:
	//  1) https://core.telegram.org/method/auth.sendCode
	PhoneCodeHash string
	// Valid numerical code from the SMS-message
	//
	// Use SetPhoneCode and GetPhoneCode helpers.
	PhoneCode string
	// Email verification code or token
	//
	// Use SetEmailVerification and GetEmailVerification helpers.
	EmailVerification EmailVerificationClass
}

// AuthSignInRequestTypeID is TL type id of AuthSignInRequest.
const AuthSignInRequestTypeID = 0x8d52a951

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

func ( *AuthSignInRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.PhoneNumber == "") {
		return false
	}
	if !(.PhoneCodeHash == "") {
		return false
	}
	if !(.PhoneCode == "") {
		return false
	}
	if !(.EmailVerification == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AuthSignInRequest from given interface.
func ( *AuthSignInRequest) ( interface {
	() ( string)
	() ( string)
	() ( string,  bool)
	() ( EmailVerificationClass,  bool)
}) {
	.PhoneNumber = .()
	.PhoneCodeHash = .()
	if ,  := .();  {
		.PhoneCode = 
	}

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

}

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

// TypeName returns name of type in TL schema.
func (*AuthSignInRequest) () string {
	return "auth.signIn"
}

// TypeInfo returns info about TL type.
func ( *AuthSignInRequest) () tdp.Type {
	 := tdp.Type{
		Name: "auth.signIn",
		ID:   AuthSignInRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "PhoneNumber",
			SchemaName: "phone_number",
		},
		{
			Name:       "PhoneCodeHash",
			SchemaName: "phone_code_hash",
		},
		{
			Name:       "PhoneCode",
			SchemaName: "phone_code",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "EmailVerification",
			SchemaName: "email_verification",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AuthSignInRequest) () {
	if !(.PhoneCode == "") {
		.Flags.Set(0)
	}
	if !(.EmailVerification == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *AuthSignInRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.signIn#8d52a951 as nil")
	}
	.PutID(AuthSignInRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AuthSignInRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode auth.signIn#8d52a951 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode auth.signIn#8d52a951: field flags: %w", )
	}
	.PutString(.PhoneNumber)
	.PutString(.PhoneCodeHash)
	if .Flags.Has(0) {
		.PutString(.PhoneCode)
	}
	if .Flags.Has(1) {
		if .EmailVerification == nil {
			return fmt.Errorf("unable to encode auth.signIn#8d52a951: field email_verification is nil")
		}
		if  := .EmailVerification.Encode();  != nil {
			return fmt.Errorf("unable to encode auth.signIn#8d52a951: field email_verification: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *AuthSignInRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.signIn#8d52a951 to nil")
	}
	if  := .ConsumeID(AuthSignInRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode auth.signIn#8d52a951: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *AuthSignInRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode auth.signIn#8d52a951 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode auth.signIn#8d52a951: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode auth.signIn#8d52a951: field phone_number: %w", )
		}
		.PhoneNumber = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode auth.signIn#8d52a951: field phone_code_hash: %w", )
		}
		.PhoneCodeHash = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode auth.signIn#8d52a951: field phone_code: %w", )
		}
		.PhoneCode = 
	}
	if .Flags.Has(1) {
		,  := DecodeEmailVerification()
		if  != nil {
			return fmt.Errorf("unable to decode auth.signIn#8d52a951: field email_verification: %w", )
		}
		.EmailVerification = 
	}
	return nil
}

// GetPhoneNumber returns value of PhoneNumber field.
func ( *AuthSignInRequest) () ( string) {
	if  == nil {
		return
	}
	return .PhoneNumber
}

// GetPhoneCodeHash returns value of PhoneCodeHash field.
func ( *AuthSignInRequest) () ( string) {
	if  == nil {
		return
	}
	return .PhoneCodeHash
}

// SetPhoneCode sets value of PhoneCode conditional field.
func ( *AuthSignInRequest) ( string) {
	.Flags.Set(0)
	.PhoneCode = 
}

// GetPhoneCode returns value of PhoneCode conditional field and
// boolean which is true if field was set.
func ( *AuthSignInRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .PhoneCode, true
}

// SetEmailVerification sets value of EmailVerification conditional field.
func ( *AuthSignInRequest) ( EmailVerificationClass) {
	.Flags.Set(1)
	.EmailVerification = 
}

// GetEmailVerification returns value of EmailVerification conditional field and
// boolean which is true if field was set.
func ( *AuthSignInRequest) () ( EmailVerificationClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .EmailVerification, true
}

// AuthSignIn invokes method auth.signIn#8d52a951 returning error if any.
// Signs in a user with a validated phone number.
//
// Possible errors:
//
//	500 AUTH_RESTART: Restart the authorization process.
//	400 PHONE_CODE_EMPTY: phone_code is missing.
//	400 PHONE_CODE_EXPIRED: The phone code you provided has expired.
//	400 PHONE_CODE_INVALID: The provided phone code is invalid.
//	406 PHONE_NUMBER_INVALID: The phone number is invalid.
//	400 PHONE_NUMBER_UNOCCUPIED: The phone number is not yet being used.
//	500 SIGN_IN_FAILED: Failure while signing in.
//
// See https://core.telegram.org/method/auth.signIn for reference.
func ( *Client) ( context.Context,  *AuthSignInRequest) (AuthAuthorizationClass, error) {
	var  AuthAuthorizationBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .Authorization, nil
}