<?php

namespace App\Http\Controllers\UserAuth;

use App\Http\Controllers\Controller;
use App\Http\Requests\User\EmailVerificationRequest;
use App\Services\Google2FaServices;


class EmailVerificationController extends Controller
{ 
    protected Google2FaServices $google2FaServices;
    public function __construct(Google2FaServices $google2FaServices)
    {
        $this->google2FaServices = $google2FaServices;
        if(auth()->check()){
            return redirect('/');
        }
    }

    public function Verify(EmailVerificationRequest $request){
        $google2FaQR = $this->google2FaServices->generateQRImage($request->email);
        $request->session()->flash('registration_data', $google2FaQR);
        // Pass the QR barcode image to our view
        return view('Dashboard.User.register', ['QR_Image' => $google2FaQR['QR_Image'], 'secret'=>$google2FaQR['google2fa_secret']]);
    }


    public function VerifyEmail(){

        if(session()->get('user_data') != ''){
            return view('Dashboard.User.verify');
        }else{
            return redirect('/');
        }
    }
}
