<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use App\Models\SyncMetadata;
use Carbon\Carbon;

class MaintenanceNotification
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        // Notificaciones de mantenimiento deshabilitadas - actualización automática eliminada
        // $maintenanceStarted = SyncMetadata::where('key', 'maintenance_started_at')->first();
        
        // if ($maintenanceStarted) {
        //     // Mantenimiento en curso
        //     session()->flash('maintenance_active', true);
        //     session()->flash('maintenance_message', 'System maintenance in progress. Some features may be temporarily unavailable.');
        // } else {
        //     // Verificar si mostrar aviso previo según configuración
        //     if (config('maintenance.notifications.show_advance_warning', false)) {
        //         $now = Carbon::now();
        //         $warningHours = config('maintenance.notifications.advance_warning_hours', [0, 6]);
        //                 
        //         if ($now->hour >= $warningHours[0] && $now->hour < $warningHours[1]) {
        //             session()->flash('maintenance_scheduled', true);
        //             session()->flash('maintenance_message', config('maintenance.notifications.advance_warning_message'));
        //             }
        //     }
        // }

        return $next($request);
    }
} 