<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;


use App\Helpers\Environment\SystemModulesHelper;
use App\Helpers\Environment\SystemFeaturesHelper;

class ValidateModuleFeature
{
    public function handle(
        Request $request, Closure $next,
        ?string $module = null,
        ...$features
    ) {
      // Validate Module
        if ($module && !SystemModulesHelper::getGuestModuleStatus($module))
            return response()->json([
                'success' => false, 'message' => 'Conexión no Permitida',
            ], 403);

        // Validar features
        foreach ($features as $feature) {
            if (!SystemFeaturesHelper::getGuestFeatureStatus($feature))
                return response()->json([
                    'success' => false, 'message' => 'Funcionalidad no disponible',
                ], 403);
        }

        return $next($request);
    }
}
