<?php

namespace App\Http\Controllers\Auth;

use App\Domains\Identity\Actions\RegisterTenantAction;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\RegisterTenantRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class RegisteredUserController extends Controller
{
    public function create(): View
    {
        return view('auth.register');
    }

    public function store(RegisterTenantRequest $request, RegisterTenantAction $registerTenant): RedirectResponse
    {
        $user = $registerTenant->execute($request->validated());

        Auth::login($user);
        $request->session()->regenerate();

        return redirect()->route('onboarding.show');
    }
}
