<?php

namespace App\Classes\Modules\Currencies\Standards\Rules\Rates;


use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Currencies\Standards\Validators\Rates\RateValidation;
use App\Classes\Modules\Currencies\DataTransferObjects\RateObject;

class CanUpdateRate extends AbstractRule
{

    /** @var RateValidation */
    private $rateValidation;

    /**
     * CanUpdateRate constructor.
     * @param RateValidation $rateValidation
     */
    public function __construct(RateValidation $rateValidation)
    {
        $this->rateValidation = $rateValidation;
    }

    /**
     * @return bool
     */
    protected function authorized(): bool
    {
        // TODO  Set Authorization rules

        if (!\Auth::user()->can('view currency_rate')) {
            return false;
        }

        return true;
    }

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

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

}