<?php

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


use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Transactions\DataTransferObjects\WaiveTransactionObject;
use App\Classes\Modules\Transactions\Standards\Validators\WaiveTransactionValidation;
use App\Classes\ValueObjects\Constants\RoleTypes;

class CanWaiveTransaction extends AbstractRule
{

    /** @var WaiveTransactionValidation */
    private $waiveTransactionValidation;


    public function __construct(WaiveTransactionValidation $waiveTransactionValidation)
    {
        $this->waiveTransactionValidation = $waiveTransactionValidation;
    }

      /**
     * @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;
            }
        }

        return false;
    }

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

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

}
