<?php

namespace App\Classes\Modules\Orders\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
use App\Http\Resources\BookingResource;
use App\Http\Resources\OrderResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FetchOrderLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Order',
            'message' => 'You have successfully retrieved an order'
        ];
    }

    /** @var CanFetchOrder */
    private $canFetchOrder;

    /** @var FetchesOrder */
    private $fetchesOrder;

    /**
     * FetchOrderLogic constructor.
     * @param CanFetchOrder $canFetchOrder
     * @param FetchesOrder $fetchesOrder
     */
    public function __construct(CanFetchOrder $canFetchOrder, FetchesOrder $fetchesOrder)
    {
        $this->canFetchOrder = $canFetchOrder;
        $this->fetchesOrder = $fetchesOrder;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {

        $this->canFetchOrder->passes();

        $query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);

        return $this->resourceResponse(new OrderResource($query));

    }

}