<?php

namespace Modules\Inventory\Services;

use App\Models\ActivityLogModel;

class StockAdjustmentService
{
    protected StockService $stock;
    protected ActivityLogModel $activity;

    public function __construct()
    {
        $this->stock    = new StockService();
        $this->activity = new ActivityLogModel();
    }

    public function create(array $input, ?int $actingUserId): array
    {
        $result = $this->stock->adjust($input, $actingUserId);
        if (! $result['success']) {
            return $result;
        }

        $adjustmentId = $result['adjustment_id'] ?? null;
        $this->activity->log(
            'stock_adjustments',
            'created',
            $actingUserId,
            'Created stock adjustment' . ($adjustmentId ? " #{$adjustmentId}" : ''),
            $adjustmentId ? (string) $adjustmentId : null
        );

        return ['success' => true, 'id' => $adjustmentId];
    }
}
