<?php

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


use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Banks\DataTransferObjects\BankMetadataObject;
use App\Classes\Modules\Banks\Standards\Validators\BankMetadataValidation;
use App\Classes\ValueObjects\Constants\RoleTypes;
use Illuminate\Support\Facades\Auth;

class CanUpdateBankMetadata extends AbstractRule
{

    /** @var BankMetadataValidation */
    private $validation;


    /**
     * CanUpdateBankMetadata constructor.
     * @param BankMetadataValidation $validation
     */
    public function __construct(BankMetadataValidation $validation)
    {
        $this->validation = $validation;
    }

    /**
     * @return bool
     */
    protected function authorized($object): bool
    {
        //cief todo: 66 - temporary workaround
        // if (!Auth::user()->can('update bank_metadata')) {
        //     return false;
        // }

        // return true;

        if (in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)) {
            return true;
        }

        return false;
    }

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

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

}
