<?php

namespace App\Classes\Modules\Accounts\Standards\Criteria;


use App\Classes\Exceptions\ResourceNotFoundException;
use App\Models\UserEmailVerification;

class EmailVerificationActiveAttemptExists
{

    /** @var UserEmailVerification */
    private $repository;

    /**
     * TokenExistsValidation constructor.
     * @param UserEmailVerification $repository
     */
    public function __construct(UserEmailVerification $repository)
    {
        $this->repository = $repository;
    }


    /**
     * @param string $token
     * @return bool
     * @throws ResourceNotFoundException
     */
    public function execute(string $token){

        if(!$this->repository->active()->where('token', $token)->first()){
            throw new ResourceNotFoundException('The email verification token has expired or doesn\'t exist');
        }

        return true;

    }

}