<?php

namespace App\Classes\Modules\Orders\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Orders\Services\RestoresOrder;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Http\Resources\OrderResource;
use App\Models\Order;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class RestoreOrderLogic extends AbstractControllerLogic
{


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

    /** @var RestoresOrder */
    private $restoresOrder;

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

    /**
     * CancelOrderLogic constructor.
     * @param RestoresOrder $restoresOrder
     * @param FetchesOrder $fetchesOrder
     */
    public function __construct(RestoresOrder $restoresOrder, FetchesOrder $fetchesOrder)
    {
        $this->restoresOrder = $restoresOrder;
        $this->fetchesOrder = $fetchesOrder;
    }

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

        /** @var Order $order */
        $order = $this->fetchesOrder->execute(['id' => $request->route('id')]);

        return $this->resourceResponse(new OrderResource($this->restoresOrder->execute($order)));

    }

}