<?php
namespace App\Support;
use PragmaRX\Google2FALaravel\Support\Authenticator;
use Log;
class Google2FAAuthenticator extends Authenticator
{
    protected function canPassWithoutCheckingOTP()
    {
        //dd($this->getUser()->passwordSecurity()->get());
        //empty($this->getUser()->passwordSecurity) || 
        // Log::info('google2faenable '.$this->getUser()->passwordSecurity->google2fa_enable);
        // Log::info('google2faenable '.$this->isEnabled());
        // Log::info('google2faenable '.$this->noUserIsAuthenticated());
        // Log::info('google2faenable '.$this->twoFactorAuthStillValid());

        // Log::info('can pass '.(!$this->getUser()->passwordSecurity->google2fa_enable ||
        // !$this->isEnabled() ||
        // $this->noUserIsAuthenticated() ||
        // $this->twoFactorAuthStillValid()));
        if(!$this->getUser()->passwordSecurity){
            //Log::info('password security ');
            return true;
        }
            
        return
            !$this->getUser()->passwordSecurity->google2fa_enable ||
            !$this->isEnabled() ||
            $this->noUserIsAuthenticated() ||
            $this->twoFactorAuthStillValid();
    }
    protected function getGoogle2FASecretKey()
    {
        $secret = $this->getUser()->passwordSecurity->{$this->config('otp_secret_column')};
        if (is_null($secret) || empty($secret)) {
            throw new InvalidSecretKey('Secret key cannot be empty.');
        }
        return $secret;
    }
}