<?php

namespace App\Listeners;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;

class HandlePackageDowngrade
{
    /**
     * Handle the event.
     */
    public function handle($event)
    {
        // Supposing an event has a hotel_id or hotel property
        $hotelId = $event->hotel_id ?? ($event->hotel->id ?? null);
        
        if ($hotelId) {
            Log::info("Triggering background cleanup for Hotel {$hotelId} due to package downgrade.");
            
            // Clean up leaked data immediately upon downgrade
            // Should be queued in production
            Artisan::call('hotel:cleanup-leaked-data', [
                'hotel_id' => $hotelId
            ]);
            
            Log::info("Successfully cleaned up restricted module data for Hotel {$hotelId}.");
        }
    }
}
