*/ final class SyncProductInco implements Action { public function __construct( private readonly ArcadiaIncoService $arcadiaIncoService, ) { } /** * @param \App\Cqs\Actions\ProductIncos\SyncProductIncoInput $input */ #[\Override] public function __invoke(ActionInput $input): SyncProductIncoOutput { Assert::isInstanceOf($input, SyncProductIncoInput::class); $inco = ProductInco::query() ->where('product_id', $input->productId->value->toString()) ->first(); if ($inco === null) { return SyncProductIncoOutput::notAssociated(); } try { $incoData = $this->arcadiaIncoService->fetchInco($inco->no_art); } catch (\RuntimeException $e) { return SyncProductIncoOutput::apiError($e->getMessage()); } if ($incoData === null) { return SyncProductIncoOutput::notFoundOnArcadia($inco->no_art); } $inco->hydrateFromArcadiaDto($incoData); $inco->saveOrFail(); return SyncProductIncoOutput::success($inco); } }