<?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\Steps\Processors\UpdateStepsProcessor;
use App\Classes\Modules\Orders\Services\FetchesOrder;
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\Services\CreatesManySteps;
use App\Classes\ValueObjects\Constants\OrderStatus;
use App\Classes\ValueObjects\Constants\Steps;
use App\Classes\Modules\Unity\Processors\GetContractObligationsProcessor;
use App\Models\Order;
use App\Models\Step;
use App\Classes\Jobs\UnityLogin;
use Config;
use Illuminate\Support\Facades\Http;


class GenerateStepsProcessor
{
    private $updatesOrderCurrentStep;

    private $createsManyStep;

    private $updateStepProcessors;

    private $getUnityContractObligationsProcessor;

    public function __construct(UpdatesOrderCurrentStepProcessor $updatesOrderCurrentStep, CreatesManySteps $createsManyStep, UpdateStepsProcessor $updateStepProcessors, GetContractObligationsProcessor $getUnityContractObligationsProcessor)
    {
        $this->updatesOrderCurrentStep = $updatesOrderCurrentStep;
        $this->createsManyStep = $createsManyStep;
        $this->updateStepProcessors = $updateStepProcessors;
        $this->getUnityContractObligationsProcessor = $getUnityContractObligationsProcessor;
    }

    public function execute(Order $order, array $contract_obligation_list=[], array $orderRoles=[]){

        $obligations = $contract_obligation_list;

        //TODO: Collect hash_id & search company module table for appointee id

        foreach($obligations as $step){
            $orderSteps[] = new StepsObject(
                 $orderRoles[0]->company_module_id,
                $step->name,
                true,
                $step->sequence??0,
                0,
                0,
                null,
                0,
                $step->hash_id
            );
        }

        $this->createsManyStep->execute($order, $orderSteps);

        $this->updatesOrderCurrentStep->execute($order->id, Steps::PACKING);

        $this->updateStepProcessors->execute(Steps::PROCESSING);

    }
}
