<?php

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

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

class CanUpdateMilestone extends AbstractRule
{
    /** @var MilestoneValidation */
    private $milestoneValidation;


    /**
     * CanUpdateMilestone constructor.
     * @param MilestoneValidation $milestoneValidation
     */
    public function __construct(MilestoneValidation $milestoneValidation)
    {
        $this->milestoneValidation = $milestoneValidation;
    }

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

    /**
     * @param MilestoneObject $object
     * @return bool
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    protected function validators($object): bool
    {
        return $this->milestoneValidation->validate($object, 'PUT');
    }

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