<?php

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

use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\Standards\Criterias\BookingsAreMergeable;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingMergeObject;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Classes\Modules\Bookings\Standards\Validators\BookingMergeValidation;

class CanMergeBooking extends AbstractRule
{

    /** @var BookingMergeValidation */
    private $bookingMergeValidation;

    /** @var BookingsAreMergeable */
    private $bookingsAreMergeable;


    /**
     * CanCreateBooking constructor.
     * @param BookingMergeValidation $bookingMergeValidation
     * @param BookingsAreMergeable $bookingsAreMergeable
     */
    public function __construct(BookingMergeValidation $bookingMergeValidation, BookingsAreMergeable $bookingsAreMergeable)
    {
        $this->bookingMergeValidation = $bookingMergeValidation;
        $this->bookingsAreMergeable = $bookingsAreMergeable;
    }

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

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

    /**
     * @param BookingMergeObject $object
     * @return bool
     * @throws ResourceNotFoundException
     */
    protected function criteria($object): bool
    {
        $this->bookingsAreMergeable->execute($object);
        return true;
    }
}