<?php

namespace App\Classes\Modules\HelpMenu\Standards\Rules;


use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Classes\Modules\HelpMenu\Standards\Validators\FeedbackUrlValidation;
use App\Classes\Modules\HelpMenu\DataTransferObjects\GenerateFeedbackUrlObject;
use Illuminate\Support\Facades\Log;

class CanGenerateFeedbackUrl extends AbstractRule
{

    /** @var FeedbackUrlValidation */
    private $feedbackUrlValidation;

    /**
     * CanGenerateFeedbackUrl constructor.
     * @param FeedbackUrlValidation $feedbackUrlValidation
     */
    public function __construct(FeedbackUrlValidation $feedbackUrlValidation)
    {
        $this->feedbackUrlValidation = $feedbackUrlValidation;
    }

    /**
     * @return bool
     */
    protected function authorized($object): bool
    {
        $user = Auth()->user();
        if($user){
            $roleToCheck = Auth()->user()->type;
            if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
                return true;
            }
        }
        else if($object->getApiKey()){
            return true;
        }

        return false;
    }

    /**
     * @param GenerateFeedbackUrlObject $object
     * @return bool
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    protected function validators($object): bool
    {
        return $this->feedbackUrlValidation->validate($object);
    }

    /**
     * @param $object
     * @return bool
     */
    protected function criteria($object): bool
    {
        return true;
    }

}
