<?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 StockOutService
{
    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,
    ): ApplyMovementResult {
        return $this->engine->apply(new ApplyMovementInput(
            tenantId: $tenantId,
            warehouseId: $warehouseId,
            itemId: $itemId,
            type: InventoryStockMovementType::StockOut,
            quantityInput: $quantity,
            actorUserId: $actorUserId,
            correlationId: $correlationId,
            idempotencyKey: $idempotencyKey,
            idempotencySource: $idempotencySource,
            unitId: $unitId,
        ));
    }
}
