<?php

declare(strict_types=1);

namespace App\Observers;

use App\Business\Integration\DbshopIntegrationService;
use App\Models\DberpInventoryTransaction;
use Illuminate\Support\Facades\DB;

class DberpInventoryTransactionObserver
{
    public function created(DberpInventoryTransaction $transaction): void
    {
        DB::afterCommit(function () use ($transaction): void {
            app(DbshopIntegrationService::class)->syncInventoryForTransaction($transaction->fresh(['product', 'productSku']));
        });
    }
}
