<?php

namespace App\Modules\Inventory\Stock\Services;

use App\Modules\Inventory\Stock\DTOs\ApplyMovementInput;
use App\Modules\Inventory\Stock\DTOs\ApplyMovementResult;
use App\Modules\Inventory\Stock\Support\InventoryStockMovementType;

final class AdjustmentService
{
    public function __construct(
        private readonly InventoryMovementApplyService $engine,
    ) {}

    public function apply(
        int $tenantId,
        int $warehouseId,
        int $itemId,
        string $signedQuantity,
        ?int $actorUserId = null,
        ?string $correlationId = null,
        ?string $idempotencyKey = null,
        string $idempotencySource = 'default',
        ?int $unitId = null,
    ): ApplyMovementResult {
        return $this->engine->apply(new ApplyMovementInput(
            tenantId: $tenantId,
            warehouseId: $warehouseId,
            itemId: $itemId,
            type: InventoryStockMovementType::Adjustment,
            quantityInput: $signedQuantity,
            actorUserId: $actorUserId,
            correlationId: $correlationId,
            idempotencyKey: $idempotencyKey,
            idempotencySource: $idempotencySource,
            unitId: $unitId,
        ));
    }
}
