<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureAgeVerified
{
    public function handle(Request $request, Closure $next): Response
    {
        $user = $request->user();

        if ($user && !$user->isAgeVerified()) {
            return response()->json([
                'message' => 'Age verification required.',
                'error' => 'age_not_verified',
            ], 403);
        }

        return $next($request);
    }
}
