<?php

namespace App\Classes\Modules\Orders\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Classes\Modules\Orders\Services\CreatesOrder;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\Orders\Standards\Rules\CanConfirmOrder;
use App\Classes\Modules\OrderSteps\Processors\GenerateOrderStepsProcessor;
use App\Classes\ValueObjects\Constants\OrderStatus;
use App\Classes\ValueObjects\Constants\OrderSteps;
use App\Classes\ValueObjects\Constants\OrderType;
use App\Http\Resources\OrderResource;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Config;

class ConfirmOrderLogic extends AbstractControllerLogic
{
    private $canConfirmOrder;

    private $generateOrderStepsProcessor;

    public function __construct(CanConfirmOrder $canConfirmOrder, GenerateOrderStepsProcessor $generateOrderStepsProcessor, FetchesOrder $fetchesOrder)
    {
        $this->canConfirmOrder = $canConfirmOrder;
        $this->generateOrderStepsProcessor = $generateOrderStepsProcessor;
        $this->fetchesOrder = $fetchesOrder;
    }

    protected function notification():array {
        return [
            'title' => 'Confirm Order',
            'message' => 'Order confirmed'
        ];
    }

    public function logic(Request $request) : JsonResponse {

        $order_object = new OrderObject(0,'','',0,0, '',$request->get('id'));

        $this->canConfirmOrder->passes($order_object);

        $order = $this->fetchesOrder->execute(['id'=>$order_object->getId()]);

        $this->generateOrderStepsProcessor->execute($order);

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