<?php

namespace App\Classes\Modules\Steps\Processors;

use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Classes\Modules\Orders\Processors\UpdatesOrderCurrentStepProcessor;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\Steps\Services\CreatesSteps;
use App\Classes\Modules\Steps\Services\FetchesSteps;
use App\Classes\Modules\Orders\Services\UpdatesCurrentStep;
use App\Classes\Modules\Orders\Standards\Rules\CanUpdateCurrentStep;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Classes\Modules\Steps\Standards\Rules\CanCreateStep;
use App\Classes\ValueObjects\Constants\OrderStatus;
use App\Classes\ValueObjects\Constants\Steps;
use App\Models\Order;
use App\Models\Step;
use Illuminate\Database\Eloquent\Model;

class CreateStepsProcessor
{
    private $canCreateStep;

    private $createsSteps;

    private $fetchesOrder;

    private $fetchesSteps;

    public function __construct(CanCreateStep $canCreateStep, FetchesOrder $fetchesOrder, FetchesSteps $fetchesSteps, CreatesSteps $createsSteps )
    {
        $this->canCreateStep = $canCreateStep;
        $this->createsSteps = $createsSteps;
        $this->fetchesOrder = $fetchesOrder;
        $this->fetchesSteps = $fetchesSteps;
    }

    /**
     * @param Order $order
     * @param string $currentStep
     * @param $appointee_id
     * @return Model
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function execute(Order $order, string $currentStep, $appointee_id){

        $stepObject = new StepsObject( $appointee_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null, 0, null);

        $this->canCreateStep->passes($stepObject);

        return $this->createsSteps->execute($order, $order_steps_object);

    }
}
