<?php

use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\EventController;
use App\Http\Controllers\Admin\MappingController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\WebhookController;
use Illuminate\Support\Facades\Route;

Route::get('/', fn () => redirect()->route('admin.dashboard'));

// Public webhook receivers (CSRF excluded via bootstrap/app.php)
Route::post('/webhook/singapay', [WebhookController::class, 'singapay'])->name('webhook.singapay');
Route::post('/webhook/faspay', [WebhookController::class, 'faspay'])->name('webhook.faspay');

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

    Route::resource('mappings', MappingController::class)->except(['show']);
    Route::post('mappings/{mapping}/test-forward', [MappingController::class, 'testForward'])->name('mappings.test-forward');

    Route::get('events', [EventController::class, 'index'])->name('events.index');
    Route::get('events/{event}', [EventController::class, 'show'])->name('events.show');
    Route::post('events/{event}/retry', [EventController::class, 'retry'])->name('events.retry');
});

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

// Default Breeze "dashboard" route — redirect to admin
Route::get('/dashboard', fn () => redirect()->route('admin.dashboard'))
    ->middleware(['auth'])->name('dashboard');

require __DIR__.'/auth.php';
