<?php

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


use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\Standards\Validators\BookingValidation;
use Illuminate\Support\Facades\Auth;

class CanUpdateBooking extends AbstractRule
{

    /** @var BookingValidation */
    private $bookingValidation;


    /**
     * CanUpdateBooking constructor.
     * @param BookingValidation $bookingValidation
     */
    public function __construct(BookingValidation $bookingValidation)
    {
        $this->bookingValidation = $bookingValidation;
    }

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

        if (!Auth::user()->can('edit booking')) {
            return false;
        }

        return true;
    }

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

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

}