<?php

namespace App\Listeners;

use Mtc\MercuryDataModels\Repositories\FeatureRepository;
use Stancl\Tenancy\Events\TenancyInitialized;

class FlushFeatureFlagCache
{
    /**
     * Reset the per-tenant feature cache when a tenant context is initialized, so
     * each request/queue-job starts clean and the next isEnabled() check reloads
     * the current tenant's features rather than reusing a previous context's.
     */
    public function handle(TenancyInitialized $event): void
    {
        FeatureRepository::flush();
    }
}
