<?php

namespace App\Classes\Modules\Orders\Services\Steps;


use App\Classes\ValueObjects\Constants\OrderSteps;
use App\Models\Order;
use Illuminate\Http\Request;

class UpdatesOrderSteps
{

    /** @var Order */
    private $repository;

    /**
     * UpdatesOrderSteps constructor.
     * @param Order $repository
     */
    public function __construct(Order $repository)
    {
        $this->repository = $repository;
    }


    /**
     * @param int $orderId
     * @param Request $request
     * @return mixed
     */
    public function execute(int $orderId, Request $request) {

        $repository = $this->repository->findOrFail($orderId);

        $class = OrderSteps::STEP_PROCESSOR[$repository->current_step];

        return (new $class($orderId, $request->input('complete_date')))->execute();

    }

}