<?php

declare(strict_types=1);

namespace App\Http\Responses;

use Illuminate\Http\Request;
use Inertia\Inertia;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Symfony\Component\HttpFoundation\Response;

class LoginResponse implements LoginResponseContract
{
    public function toResponse($request): Response
    {
        /** @var Request $request */
        $user = $request->user();

        if ($user && $user->hasRole('admin')) {
            $url = 'https://'.config('app.domains.admin').'/dashboard';

            return Inertia::location($url);
        }

        return redirect()->intended('/dashboard');
    }
}
