<?php

use App\Http\Controllers\Auth\RoleRegistrationController;
use App\Http\Controllers\DashboardController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Role-Specific Public Registration Routes
|--------------------------------------------------------------------------
|
| These routes expose a dedicated registration form for each user role.
| All forms are guest-only. Authenticated users are redirected to their
| role-specific dashboard.
|
| Route naming convention: register.role.{role}
|
*/

// ============================================================================
// GUEST-ONLY REGISTRATION FORMS
// ============================================================================

Route::middleware('guest')->prefix('register')->name('register.role.')->group(function () {

    // Member
    Route::get('/member',  [RoleRegistrationController::class, 'showMember'])->name('member');
    Route::post('/member', [RoleRegistrationController::class, 'storeMember'])->name('member.store');

    // Trainer
    Route::get('/trainer',  [RoleRegistrationController::class, 'showTrainer'])->name('trainer');
    Route::post('/trainer', [RoleRegistrationController::class, 'storeTrainer'])->name('trainer.store');

    // Trainee
    Route::get('/trainee',  [RoleRegistrationController::class, 'showTrainee'])->name('trainee');
    Route::post('/trainee', [RoleRegistrationController::class, 'storeTrainee'])->name('trainee.store');

    // Mentor
    Route::get('/mentor',  [RoleRegistrationController::class, 'showMentor'])->name('mentor');
    Route::post('/mentor', [RoleRegistrationController::class, 'storeMentor'])->name('mentor.store');

    // Mentee
    Route::get('/mentee',  [RoleRegistrationController::class, 'showMentee'])->name('mentee');
    Route::post('/mentee', [RoleRegistrationController::class, 'storeMentee'])->name('mentee.store');

    // Partner
    Route::get('/partner',  [RoleRegistrationController::class, 'showPartner'])->name('partner');
    Route::post('/partner', [RoleRegistrationController::class, 'storePartner'])->name('partner.store');

    // Contributor
    Route::get('/contributor',  [RoleRegistrationController::class, 'showContributor'])->name('contributor');
    Route::post('/contributor', [RoleRegistrationController::class, 'storeContributor'])->name('contributor.store');

    // Health Marketor
    Route::get('/health-marketor',  [RoleRegistrationController::class, 'showHealthMarketor'])->name('health-marketor');
    Route::post('/health-marketor', [RoleRegistrationController::class, 'storeHealthMarketor'])->name('health-marketor.store');

    // Shared success page (approval-required roles redirect here)
    Route::get('/success', [RoleRegistrationController::class, 'success'])->name('success');
});

// ============================================================================
// AUTHENTICATED USERS — redirect away from registration
// ============================================================================

Route::middleware('auth')->prefix('register')->group(function () {
    Route::get('/{role}', [DashboardController::class, 'index'])
        ->where('role', 'member|trainer|trainee|mentor|mentee|partner|contributor|health-marketor');
});

// ============================================================================
// LEGACY REDIRECT — /partners/become-partner → /register/partner (HTTP 301)
// ============================================================================

Route::redirect('/partners/become-partner', '/register/partner', 301);
