<?php

declare(strict_types=1);

namespace Builder\Core\Http\Controllers\Auth;

use Builder\Core\Foundation\Middleware\BuilderAuth;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

final class LogoutController
{
    public function __invoke(Request $request): RedirectResponse
    {
        $guard = BuilderAuth::guard();

        Auth::guard($guard)->logout();

        $request->session()->invalidate();
        $request->session()->regenerateToken();

        return redirect()->route('builder.login');
    }
}
