<?php

use App\Http\Controllers\Billing\BillingPaymentController;
use App\Http\Controllers\Billing\PakasirController;
use App\Http\Controllers\Billing\PayPalController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\Web\SiteController;
use Illuminate\Support\Facades\Route;

Route::get('/', [SiteController::class, 'home'])->name('home');
Route::get('/robots.txt', [SiteController::class, 'robotsTxt'])->name('robots');
Route::get('/sitemap.xml', [SiteController::class, 'sitemapXml'])->name('sitemap');
Route::get('/browse', [SiteController::class, 'browse'])->name('browse');
Route::get('/api-docs', [SiteController::class, 'apiDocs'])->name('api-docs');
Route::get('/emoji/{slug}', [SiteController::class, 'emojiDetail'])->name('emoji-detail');

Route::get('/pricing', [SiteController::class, 'pricing'])->name('pricing');
Route::post('/pricing/currency', [SiteController::class, 'setPricingCurrency'])->name('pricing.currency');
Route::get('/download', [SiteController::class, 'download'])->name('download');
Route::get('/downloads/version.json', [SiteController::class, 'downloadVersionJson'])->name('downloads.version');
Route::get('/downloads/dewemoji-latest.apk', [SiteController::class, 'downloadLatestApk'])->name('downloads.latest-apk');
Route::get('/.well-known/assetlinks.json', [SiteController::class, 'assetLinks'])->name('assetlinks');
Route::get('/support', [SiteController::class, 'support'])->name('support');
Route::get('/privacy', [SiteController::class, 'privacy'])->name('privacy');
Route::get('/terms', [SiteController::class, 'terms'])->name('terms');
Route::get('/profile', function () {
    return redirect()->route('profile.edit');
})->middleware('auth');

Route::get('/{categorySlug}', [SiteController::class, 'category'])
    ->where('categorySlug', 'all|smileys|people|animals|food|travel|activities|objects|symbols|flags')
    ->name('category');
Route::get('/{categorySlug}/{subcategorySlug}', [SiteController::class, 'categorySubcategory'])
    ->where('categorySlug', 'all|smileys|people|animals|food|travel|activities|objects|symbols|flags')
    ->where('subcategorySlug', '[a-z0-9\\-]+')
    ->name('category-subcategory');

Route::middleware('auth')->group(function () {
    Route::post('/billing/paypal/create', [PayPalController::class, 'createSubscription'])
        ->middleware('verified')
        ->name('billing.paypal.create');
    Route::get('/billing/paypal/return', [PayPalController::class, 'return'])->name('billing.paypal.return');
    Route::post('/billing/pakasir/create', [PakasirController::class, 'createTransaction'])
        ->middleware('verified')
        ->name('billing.pakasir.create');
    Route::post('/billing/pakasir/cancel', [PakasirController::class, 'cancelPending'])
        ->middleware('verified')
        ->name('billing.pakasir.cancel');
    Route::post('/billing/pakasir/status', [PakasirController::class, 'paymentStatus'])
        ->middleware('verified')
        ->name('billing.pakasir.status');
    Route::post('/billing/payments/{payment}/resume', [BillingPaymentController::class, 'resume'])
        ->middleware('verified')
        ->name('billing.payments.resume');

    Route::get('/dashboard/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/dashboard/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/dashboard/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

require __DIR__.'/auth.php';
