<?php

namespace App\Console\Commands;

use App\Services\InventoryService;
use App\Services\LocationInventoryService;
use Illuminate\Console\Command;

class CleanupExpiredStockReservations extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'inventory:cleanup-expired-reservations';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Clean up expired stock reservations';

    /**
     * Execute the console command.
     */
    public function handle(LocationInventoryService $locationInventory, InventoryService $inventoryService): int
    {
        $this->info('Cleaning up expired stock reservations...');

        $count = $locationInventory->useLocationInventory()
            ? $locationInventory->cleanupExpiredReservations()
            : $inventoryService->cleanupExpiredReservations();

        if ($count > 0) {
            $this->info("Cleaned up {$count} expired reservation(s).");
        } else {
            $this->info('No expired reservations found.');
        }

        return Command::SUCCESS;
    }
}
