<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;

Route::get('/', function () {
    return redirect()->route('admin.login');
});

Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.submit');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    // API documentation (Swagger)
    Route::get('/api-docs', [\App\Http\Controllers\Admin\ApiDocumentationController::class, 'index'])->name('api.docs');
    Route::get('/api-docs/swagger.json', [\App\Http\Controllers\Admin\ApiDocumentationController::class, 'swagger'])->name('api.swagger');

    Route::middleware('auth:admin')->group(function () {
        Route::get('/', [DashboardController::class, 'index'])->name('dashboard');

        Route::resource('users', \App\Http\Controllers\Admin\UserController::class);

        Route::resource('admins', \App\Http\Controllers\Admin\AdminController::class);
        Route::resource('notifications', \App\Http\Controllers\Admin\NotificationController::class);

        // Content Management
        Route::resource('categories', \App\Http\Controllers\Admin\CategoryController::class);
        Route::resource('contents', \App\Http\Controllers\Admin\ContentController::class);
        Route::resource('playlists', \App\Http\Controllers\Admin\PlaylistController::class);

        // Commerce
        Route::resource('packages', \App\Http\Controllers\Admin\PackageController::class); // Alias for subscription-packages
        Route::resource('subscription-packages', \App\Http\Controllers\Admin\PackageController::class);
        Route::resource('payments', \App\Http\Controllers\Admin\PaymentController::class);
        Route::resource('discount-codes', \App\Http\Controllers\Admin\DiscountCodeController::class);

        // Support & Gamification
        Route::resource('support-tickets', \App\Http\Controllers\Admin\SupportTicketController::class);
        Route::resource('feedbacks', \App\Http\Controllers\Admin\FeedbackController::class); // Keep for backward compatibility if needed, or redirect
        Route::resource('badges', \App\Http\Controllers\Admin\BadgeController::class);

        Route::resource('logs', \App\Http\Controllers\Admin\LogController::class);

        Route::get('settings', [\App\Http\Controllers\Admin\SettingController::class, 'index'])->name('settings.index');
        Route::post('settings', [\App\Http\Controllers\Admin\SettingController::class, 'update'])->name('settings.update');

        // کدهای فعالسازی OTP
        Route::get('otp-codes', [\App\Http\Controllers\Admin\OtpCodeController::class, 'index'])->name('otp-codes.index');
        Route::post('otp-codes/generate', [\App\Http\Controllers\Admin\OtpCodeController::class, 'generate'])->name('otp-codes.generate');
        Route::post('otp-codes/{otpCode}/extend', [\App\Http\Controllers\Admin\OtpCodeController::class, 'extend'])->name('otp-codes.extend');
        Route::post('otp-codes/cleanup', [\App\Http\Controllers\Admin\OtpCodeController::class, 'cleanup'])->name('otp-codes.cleanup');
    });
});
