<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Response;

class SetDatabaseTimezone
{
    public function handle(Request $request, Closure $next): Response
    {
        $timezone = config('app.timezone', '+03:00');

        try {
            DB::statement("SET time_zone = '{$timezone}'");
        } catch (\Exception $e) {
            // Silently fail if MySQL doesn't support timezone
        }

        return $next($request);
    }
}
