<?php

namespace App\Classes\Modules\Accounts\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Accounts\Processors\GenerateEmailVerificationAttemptProcessor;
use App\Classes\Modules\Accounts\Services\FetchesUser;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ResendEmailVerificationLogic extends AbstractControllerLogic
{

    public function notification(): array
    {
        return [
            'title' => 'Resend Verification Email',
            'message' => 'Successfully resent a new verification email'
        ];
    }

    /** @var FetchesUser */
    private $fetchesUser;

    /** @var GenerateEmailVerificationAttemptProcessor */
    private $generateEmailVerificationAttemptProcessor;

    /**
     * ResendEmailVerificationLogic constructor.
     * @param FetchesUser $fetchesUser
     * @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor
     */
    public function __construct(FetchesUser $fetchesUser, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor)
    {
        $this->fetchesUser = $fetchesUser;
        $this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor;
    }

    public function logic(Request $request) : JsonResponse {

        /** @var User $user */
        $user = $this->fetchesUser->execute(['id' => $request->input('user_id')]);

        $this->generateEmailVerificationAttemptProcessor->execute($user);

        return $this->response([]);

    }

}