<?php

namespace App\Classes\Modules\Orders\ControllersLogic;

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

class UpdateOrderLogic extends AbstractControllerLogic
{

    protected function notification(): array
    {
        return [
            'title' => 'Update Order',
            'message' => 'You have successfully update the order'
        ];
    }

    private $updateOrderReference;
    private $fetchesOrder;

    public function __construct(UpdateOrderReference $updateOrderReference, FetchesOrder $fetchesOrder)
    {
        $this->updateOrderReference = $updateOrderReference;
        $this->fetchesOrder = $fetchesOrder;
    }

    protected function logic(Request $request): JsonResponse
    {
        $reference_id = $request->input('reference_id');

        $order = $this->fetchesOrder->execute(['id' => $request->route('id')]);

        $order = $this->updateOrderReference->execute($order, $reference_id);

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

    }
}
