<?php

namespace App\Classes\Modules\PackingList\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\OrderSteps;
use App\Classes\ValueObjects\Constants\Steps;
use App\Classes\Modules\Unity\Processors\GetContractObligationsProcessor;
use App\Models\CompanyModule;
use App\Models\Order;
use App\Models\Step;
use App\Classes\Jobs\UnityLogin;
use Config;
use Illuminate\Support\Facades\Http;
use function PHPSTORM_META\map;


class GenerateShippingOrderStepsProcessor
{
    /** @var CreatesManySteps  */
    private $createsManyStep;

    /** @var UpdateStepsProcessor  */
    private $updateStepProcessors;

    /**
     * GenerateShippingOrderStepsProcessor constructor.
     * @param CreatesManySteps $createsManyStep
     * @param UpdateStepsProcessor $updateStepProcessors
     */
    public function __construct(CreatesManySteps $createsManyStep, UpdateStepsProcessor $updateStepProcessors)
    {
        $this->createsManyStep = $createsManyStep;
        $this->updateStepProcessors = $updateStepProcessors;
    }


    public function execute(Steppable $owner, CompanyModule $appointee, array $contract_obligation_list = []){

        $obligations = $contract_obligation_list;

        $this->createsManyStep->execute($owner, array_map(function($obligation) use ($appointee) {
            return new StepsObject($appointee->id, $obligation->name,true, $step->sequence??0, 0,0, null,0, $step->hash_id);
            }, $obligations));

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

    }
}
