<?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 StockInService
{
    public function __construct(
        private readonly InventoryMovementApplyService $engine,
    ) {}

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