<?php

namespace App\Http\Middleware;

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

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

        if ($user && ($user->must_complete_profile || $user->must_change_password)) {
            return redirect()->route('profile.complete.edit');
        }

        return $next($request);
    }
}
