<?php

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


use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Milestones\Standards\Validators\MilestoneRewardValidation;
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
use Illuminate\Support\Facades\Auth;

class CanAssignReward extends AbstractRule
{

    /** @var MilestoneRewardValidation */
    private $milestoneRewardValidation;


    /**
     * CanAssignReward constructor.
     * @param MilestoneRewardValidation $milestoneRewardValidation
     */
    public function __construct(MilestoneRewardValidation $milestoneRewardValidation)
    {
        $this->milestoneRewardValidation = $milestoneRewardValidation;
    }

    /**
     * @return bool
     */
    protected function authorized($object): bool
    {
        if (!Auth::user()->can('edit milestone')) {
            return false;
        }
        return true;
    }

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

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

}
