<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\CoachRegisterRequest;
use App\Services\Auth\RegistrationService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class CoachRegisterController extends Controller
{
    public function __construct(private readonly RegistrationService $registrationService)
    {
    }

    public function create(): View
    {
        return view('auth.register-coach');
    }

    public function store(CoachRegisterRequest $request): RedirectResponse
    {
        $user = $this->registrationService->registerCoach($request->validated());

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

        return redirect()->route('coach.pending');
    }
}
