<?php

namespace App\Classes\Modules\Orders\Processors;


use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\Orders\DataTransferObjects\StepObject;
use App\Classes\Modules\Orders\Services\Steps\GenerateOrderSteps;
use App\Classes\ValueObjects\Constants\OrderSteps;
use Illuminate\Http\JsonResponse;

class ConfirmsOrder extends AbstractStepProcessor
{

    /** @var string  */
    const STEP_REFERENCE = OrderSteps::ORDER_PROCESSING_STEP;

    /** @var int */
    private $orderId;

    /** @var StepObject */
    private $step;

    /**
     * WarehousePackOrder constructor.
     * @param int $orderId
     * @param string $completeDate
     */
    public function __construct(int $orderId, string $completeDate = null)
    {
        $this->orderId = $orderId;
        $this->step = new StepObject(self::STEP_REFERENCE, $completeDate);

    }

    /**
     * @return bool
     */
    public function validator(): bool {
        return true;
    }


    /**
     * @return JsonResponse
     * @throws InternalServerErrorException
     * @throws \App\Classes\Modules\Accounts\Exceptions\CannotCreateOrderStepsException
     */
    public function execute(): JsonResponse {

        (new generateOrderSteps())->execute($this->orderId);

        return $this->handler($this->orderId, $this->step);
    }

}