<?php

namespace App\Classes\Modules\Bookings\ControllersLogic;

use App\Classes\Modules\Bookings\Services\CancelsBooking;
use App\Classes\Modules\Bookings\Services\RestoresBooking;
use App\Http\Resources\BookingResource;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Bookings\Services\FetchesBooking;

use App\Classes\Modules\Bookings\Standards\Rules\CanDeleteBooking;
use App\Classes\Modules\Bookings\Services\DeletesBooking;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class RestoreBookingLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Restore Booking',
            'message' => 'You have successfully restored the Booking'
        ];
    }

    /** @var CanDeleteBooking */
    private $canDeleteBooking;

    /** @var FetchesBooking */
    private $fetchesBooking;

    /** @var RestoresBooking */
    private $restoresBooking;

    /**
     * RestoreBookingLogic constructor.
     * @param CanDeleteBooking $canDeleteBooking
     * @param FetchesBooking $fetchesBooking
     * @param RestoresBooking $restoresBooking
     */
    public function __construct(CanDeleteBooking $canDeleteBooking, FetchesBooking $fetchesBooking, RestoresBooking $restoresBooking)
    {
        $this->canDeleteBooking = $canDeleteBooking;
        $this->fetchesBooking = $fetchesBooking;
        $this->restoresBooking = $restoresBooking;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function logic(Request $request) : JsonResponse
    {
        $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);

        $this->restoresBooking->execute($booking);

        return $this->resourceResponse(new BookingResource($booking));
    }

}