<?php

use App\Http\Controllers\AdminBackgroundGenerationController;
use App\Http\Controllers\AdminDashboardController;
use App\Http\Controllers\FrontHomeController;
use App\Http\Controllers\FrontPagesController;
use App\Http\Controllers\SocialAuthController;
use App\Http\Controllers\UserDashboardController;
use App\Http\Controllers\UserPurchaseController;
use App\Http\Middleware\AdminMiddleware;
use Illuminate\Support\Facades\Route;

if (App::environment('local')) {

    Route::prefix('auth')->group(function () {

        Route::prefix('google')->group(function () {

            Route::get('redirect', [SocialAuthController::class, 'redirectToGoogle'])->name('auth.google.redirect');

            Route::get('callback', [SocialAuthController::class, 'handleGoogleCallback'])->name('auth.google.callback');
        });
    });

    Route::middleware(['auth', 'verified'])->group(function () {

        Route::get('dashboard', [UserDashboardController::class, 'index'])->name('dashboard');

        Route::prefix('subscribe')->group(function () {

            Route::get('success', [UserPurchaseController::class, 'subscribeSuccess'])->name('subscribe.success');

            Route::get('cancelled', [UserPurchaseController::class, 'subscribeCancelled'])->name('subscribe.cancelled');
        });

        Route::prefix('purchase')->group(function () {

            Route::get('success', [UserPurchaseController::class, 'purchaseSuccess'])->name('purchase.success');

            Route::get('cancelled', [UserPurchaseController::class, 'purchaseCancelled'])->name('purchase.cancelled');
        });

        Route::prefix('admin')->middleware([AdminMiddleware::class])->group(function () {
            Route::get('/', [AdminDashboardController::class, 'index'])->name('admin.dashboard');

            Route::prefix('background-generation')->group(function () {
                Route::get('/', [AdminBackgroundGenerationController::class, 'index'])->name('admin.background-generation');

                Route::post('generate', [AdminBackgroundGenerationController::class, 'generate'])
                    ->name('admin.background-generation.generate');

                Route::post('save', [AdminBackgroundGenerationController::class, 'save'])
                    ->name('admin.background-generation.save');

                Route::post('delete/{id}', [AdminBackgroundGenerationController::class, 'delete'])
                    ->name('admin.background-generation.delete');
            });
        });
    });

    require __DIR__.'/settings.php';
    require __DIR__.'/auth.php';
}

Route::get('/', [FrontHomeController::class, 'index'])->name('home');

Route::get('/privacy', [FrontPagesController::class, 'privacy'])->name('privacy');
Route::get('/terms', [FrontPagesController::class, 'terms'])->name('terms');
