<?php

namespace App\Classes\Modules\Orders\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Orders\Services\CancelsOrder;
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 CancelOrderLogic extends AbstractControllerLogic
{


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

    /** @var CancelsOrder */
    private $cancelsOrder;

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

    /**
     * CancelOrderLogic constructor.
     * @param CancelsOrder $cancelsOrder
     * @param FetchesOrder $fetchesOrder
     */
    public function __construct(CancelsOrder $cancelsOrder, FetchesOrder $fetchesOrder)
    {
        $this->cancelsOrder = $cancelsOrder;
        $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->cancelsOrder->execute($order)));

    }

}