<?php

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


use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\User;
use App\Models\UserEmailVerification;

class UnverifiedUserEmail
{

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

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


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

        if(!$this->repository->status === ApprovalStatus::PENDING_VERIFICATION){
            throw new MalformedRequestException('The user email address has been verified already');
        }

        return true;

    }

}