<?php

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

use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Vouchers\Standards\Validators\VoucherValidation;
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherObject;
use App\Classes\ValueObjects\Constants\RoleTypes;
use Illuminate\Support\Facades\Auth;
use App\Classes\ValueObjects\Constants\Vouchers;

class CanCreateVoucher extends AbstractRule
{

    /** @var VoucherValidation */
    private $voucherValidation;

    /**
     * CanCreateVoucher constructor.
     * @param VoucherValidation $voucherValidation
     */
    public function __construct(VoucherValidation $voucherValidation)
    {
        $this->voucherValidation = $voucherValidation;
    }

    /**
     *  @param CreateVoucherObject $object
     *  @return bool
     */
    protected function authorized($object): bool
    {
        $isAuthorized = true;
        // switch ($object->getVoucherCode()) {
        //     case Vouchers::SORRY_50:
        //     case Vouchers::SORRY_100:
        //     case Vouchers::SORRY_200:
        //         // $isAuthorized = Auth::user()->can('add voucher');
        //         $isAuthorized = in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES);
        //         break;
        //     default:
        //         $isAuthorized = true;
        //         break;
        // }
        if($object->getIsVoucherCodeUnique()){
            $isAuthorized = in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES);
        }
        return $isAuthorized;
    }

    /**
     * @param CreateVoucherObject $object
     * @return bool
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    protected function validators($object): bool
    {
        return true;
    }

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