<?php

namespace App\Classes\Modules\Segments\Processors;


use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use TimeHunter\LaravelGoogleReCaptchaV3\Core\GoogleReCaptchaV3Response;
use TimeHunter\LaravelGoogleReCaptchaV3\Facades\GoogleReCaptchaV3;

class RiskAnalysisProcessor
{

    /** @var AssignSegmentProcessor */
    private $assignSegmentProcessor;

    /**
     * RiskAnalysisProcessor constructor.
     * @param AssignSegmentProcessor $assignSegmentProcessor
     */
    public function __construct(AssignSegmentProcessor $assignSegmentProcessor)
    {
        $this->assignSegmentProcessor = $assignSegmentProcessor;
    }


    function execute(User $user, string $token){
        $captchaToken = GoogleReCaptchaV3::verifyResponse($token);

        if($captchaToken->getScore() < 0.6 && !in_array('timeout-or-duplicate', $captchaToken->getErrorCodes())){
            $this->assignSegmentProcessor->execute($user->company()->first(), 18);
        }
    }

}