<?php

use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Controllers\PaymentProcessController;

/*
|--------------------------------------------------------------------------
| Finance & Payment Routes
|--------------------------------------------------------------------------
| Handles all checkout, callbacks, and financial dashboard routing.
*/

// --- 1. General Finance Dashboard (Requires Login) ---
Route::middleware(['auth', 'verified'])->prefix('finance')->name('finance.')->group(function () {
    Route::get('/', function () {
        return Inertia::render('Home'); // Placeholder, create Finance/Index later
    })->name('index');
});

// --- 2. Payment Processing Routes ---
Route::prefix('payment')->name('payment.')->group(function () {
    
    // Checkout Action (Must be logged in to pay)
    Route::post('/checkout', [PaymentProcessController::class, 'checkout'])
        ->middleware('auth')
        ->name('process');
        
     // ---  Pay an existing pending order ---
    Route::post('/pay-pending/{order}', [PaymentProcessController::class, 'payPendingOrder'])
        ->middleware('auth')
        ->name('pay.pending');

    // Callback Action (MUST be completely OPEN so SSLCommerz/bKash can hit it)
    Route::match(['get', 'post'], '/callback/{gateway}', [PaymentProcessController::class, 'callback'])
        ->name('callback');

});