let mobileTwoFactorChecker = 0;

const AuthenticationErrors = {
	OperatingSystemNotSupported: "不支援的作業系統",
};

const AuthenticationService = {
	verifyWindows2FA: () => {
		if (os !== "Win32" && os !== "Win64") {
			alert(`${AuthenticationErrors.OperatingSystemNotSupported}: ${os}`);
			CurrentUser.signOut();
		}

		Logger.logInfo(
			`檢測 ${deviceName} 憑證中... userId=${userId}, clientId=${clientIp}`,
		);

		if (!signatureService) {
			alert("載入憑證簽章元件失敗. 請確認是否已安裝簽章元件");
			CurrentUser.signOut();
		} else {
			const testSignature = signatureService.FSCAPIKGISign_eDDA(
				userId,
				"cert-check",
				signatureType,
				certType,
				algothrim,
				encoding,
			);

			if (!testSignature) {
				alert(
					`請檢查憑證是否匯入! 錯誤代碼: ${parseInt(ServiSign_GetErrorCode())}`,
				);
				CurrentUser.signOut();
			}
		}
	},

	verifyMobile2FA: () => {
		callbackAction = "auth";
		Logger.logInfo(
			`檢測 ${deviceName} 憑證中... userId=${userId}, clientId=${clientIp}`,
        );

        if (mobileTwoFactorChecker === 0) { 
            setInterval(() => {
                if (twoFactorSignature === '') {
                    alert('無法取得手機憑證');
                    CurrentUser.signOut();
                }
            }, 5_000);
        }
        
		SignatureHandler.requestForMobile("2fa");
	},
};
