<?php

use App\Http\Controllers\Guest\AuthController;
use App\Http\Controllers\Guest\HomeController;
use App\Http\Controllers\Guest\LocaleController;
use App\Http\Controllers\ShopAuthController;
use App\Http\Controllers\ShopOrderController;
use App\Http\Controllers\ShopDashboardController;
use Illuminate\Support\Facades\Route;

Route::post('/webhooks/stripe', [\App\Http\Controllers\WebhookController::class, 'stripe'])->name('webhooks.stripe');

Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/courses/{course:slug}', [HomeController::class, 'show'])->name('courses.show');

Route::middleware('guest')->group(function () {
    Route::get('login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('login', [AuthController::class, 'storeLogin']);
    Route::get('register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('register', [AuthController::class, 'storeRegister']);
});

Route::post('logout', [AuthController::class, 'destroy'])->middleware('auth')->name('logout');

Route::get('locale/{locale}', [LocaleController::class, 'switch'])->name('locale.switch');

Route::get('/privacy-policy', [App\Http\Controllers\Guest\LegalPageController::class, 'show'])->defaults('slug', 'privacy-policy')->name('legal.privacy');
Route::get('/terms-and-conditions', [App\Http\Controllers\Guest\LegalPageController::class, 'show'])->defaults('slug', 'terms-and-conditions')->name('legal.terms');
Route::get('/about-us', [App\Http\Controllers\Guest\LegalPageController::class, 'show'])->defaults('slug', 'about-us')->name('legal.about');
Route::get('/contact-us', [App\Http\Controllers\Guest\ContactController::class, 'show'])->name('contact');

// Public Certificate Verification
Route::get('/verify-certificate', [App\Http\Controllers\Public\VerificationController::class, 'index'])->name('certificate.verify');

// Business Routes
Route::middleware('guest:business')->group(function () {
    Route::get('business/register', [BusinessAuthController::class, 'showRegister'])->name('business.register');
    Route::post('business/register', [BusinessAuthController::class, 'register']);
    Route::get('business/login', [BusinessAuthController::class, 'showLogin'])->name('business.login');
    Route::post('business/login', [BusinessAuthController::class, 'login']);
});

Route::middleware('auth:business')->group(function () {
    Route::post('business/logout', [BusinessAuthController::class, 'logout'])->name('business.logout');
    Route::get('business/dashboard', [BusinessDashboardController::class, 'index'])->name('business.dashboard');
    
    Route::resource('business/products', BusinessProductController::class, ['as' => 'business']);
    Route::resource('business/sales', BusinessSaleController::class, ['as' => 'business'])->only(['index', 'create', 'store']);
    Route::resource('business/repairs', BusinessRepairController::class, ['as' => 'business']);
    Route::resource('business/second-hand', BusinessSecondHandController::class, ['as' => 'business']);
    Route::resource('business/unlock-orders', BusinessUnlockOrderController::class, ['as' => 'business']);
    
    Route::get('business/subscription', [BusinessSubscriptionController::class, 'index'])->name('business.subscription.index');
    Route::resource('business/payments', BusinessPaymentController::class, ['as' => 'business']);
});


Route::middleware(['auth'])->group(function () {
    // Enrollment
    Route::post('/courses/{course:slug}/enroll', [App\Http\Controllers\Student\EnrollmentController::class, 'store'])->name('enroll.store');

    // Reviews
    Route::post('/courses/{course:slug}/reviews', [App\Http\Controllers\Student\ReviewController::class, 'store'])->name('student.reviews.store');

    // Student Panel
    Route::prefix('student')->name('student.')->group(function () {
        Route::get('/courses', [App\Http\Controllers\Student\CourseController::class, 'index'])->name('courses.index');
        Route::get('/courses/{course:slug}', [App\Http\Controllers\Student\CourseController::class, 'show'])->name('courses.show');
    });
});
