<?php

use App\Http\Controllers\MomoCallbackController;
use App\Http\Controllers\PaymentConfigurationController;
use Illuminate\Support\Facades\Route;

/**
 * Payment Configuration Routes
 * 
 * All routes are protected by auth and role middleware.
 * Only Super Manager role can access these routes.
 * 
 * Route naming convention: config.payment.{action}
 * 
 * @package PaymentConfigurationModule
 * @author SSHIA Development Team
 */

// ============================================================================
// MTN MoMo Global Callback — NO auth, NO CSRF (excluded in bootstrap/app.php)
// ============================================================================

Route::post('/payments/momo/callback', [MomoCallbackController::class, 'handle'])
    ->name('payments.momo.callback');

Route::middleware(['auth', 'role:Super Manager'])->prefix('config/payment')->name('config.payment.')->group(function () {
    
    /**
     * Dashboard / Index
     * Shows configuration status, statistics, and recent logs.
     * 
     * Method: GET
     * Route: /config/payment
     * Name: config.payment.index
     */
    Route::get('/', [PaymentConfigurationController::class, 'index'])->name('index');

    /**
     * Create Configuration Form
     * Shows the form for creating new payment configuration.
     * 
     * Method: GET
     * Route: /config/payment/create
     * Name: config.payment.create
     */
    Route::get('/create', [PaymentConfigurationController::class, 'create'])->name('create');

    /**
     * Store New Configuration
     * Saves new payment configuration to database.
     * 
     * Method: POST
     * Route: /config/payment
     * Name: config.payment.store
     */
    Route::post('/', [PaymentConfigurationController::class, 'store'])->name('store');

    /**
     * Edit Configuration Form
     * Shows the form for editing existing configuration.
     * 
     * Method: GET
     * Route: /config/payment/edit
     * Name: config.payment.edit
     */
    Route::get('/edit', [PaymentConfigurationController::class, 'edit'])->name('edit');

    /**
     * Update Configuration
     * Updates existing payment configuration.
     * 
     * Method: PUT/PATCH
     * Route: /config/payment
     * Name: config.payment.update
     */
    Route::put('/', [PaymentConfigurationController::class, 'update'])->name('update');
    Route::patch('/', [PaymentConfigurationController::class, 'update'])->name('update.patch');

    /**
     * Test Connection
     * Tests API connectivity for Collection or Disbursement API.
     * 
     * Method: POST
     * Route: /config/payment/test
     * Name: config.payment.test
     * Parameter: type (collection|disbursement)
     */
    Route::post('/test', [PaymentConfigurationController::class, 'testConnection'])->name('test');

    /**
     * View Test Interface
     * Shows the test interface for API connections.
     * 
     * Method: GET
     * Route: /config/payment/test
     * Name: config.payment.test-interface
     */
    Route::get('/test-interface', [PaymentConfigurationController::class, 'test'])->name('test-interface');

    /**
     * View API Logs
     * Shows paginated list of API interaction logs.
     * 
     * Method: GET
     * Route: /config/payment/logs
     * Name: config.payment.logs
     */
    Route::get('/logs', [PaymentConfigurationController::class, 'logs'])->name('logs');

    /**
     * View Single Log Entry (AJAX)
     * Returns detailed log information.
     * 
     * Method: GET
     * Route: /config/payment/logs/{log}
     * Name: config.payment.log-show
     */
    Route::get('/logs/{log}', [PaymentConfigurationController::class, 'showLog'])->name('log-show');

    /**
     * View Integration Documentation
     * Shows documentation for using PaymentService in other modules.
     * 
     * Method: GET
     * Route: /config/payment/documentation
     * Name: config.payment.documentation
     */
    Route::get('/documentation', [PaymentConfigurationController::class, 'documentation'])->name('documentation');

    /**
     * Delete Configuration
     * Removes the active payment configuration.
     * 
     * Method: DELETE
     * Route: /config/payment
     * Name: config.payment.destroy
     */
    Route::delete('/', [PaymentConfigurationController::class, 'destroy'])->name('destroy');
});
