<?php

namespace App\Console\Commands;

use App\Services\InventoryService;
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(InventoryService $inventoryService): int
    {
        $this->info('Cleaning up expired stock reservations...');

        $count = $inventoryService->cleanupExpiredReservations();

        if ($count > 0) {
            $this->info("Cleaned up {$count} expired reservation(s).");
        } else {
            $this->info('No expired reservations found.');
        }

        return Command::SUCCESS;
    }
}
