<?php

use Illuminate\Support\Facades\Route;
use Mtc\Modules\B2B\Http\Controllers\TradeAccountController;
use Mtc\Modules\B2B\Http\Controllers\TradeRegistrationController;
use Mtc\Modules\B2B\Http\Middleware\RequireTradeCustomer;

Route::middleware(['web'])->prefix('trade')->group(function () {
    // Public registration
    Route::get('/register', [TradeRegistrationController::class, 'showForm'])->name('b2b.register');
    Route::post('/register', [TradeRegistrationController::class, 'submitForm'])->name('b2b.register.submit');

    // Authenticated trade customer routes — RequireTradeCustomer validates auth,
    // attaches the TradeCustomer model to the request, and enforces the
    // pay_on_account_enabled feature flag per-request (safe with route:cache).
    Route::middleware(RequireTradeCustomer::class)->group(function () {
        Route::get('/account/orders', [TradeAccountController::class, 'outstandingOrders'])->name('b2b.account.orders');
        Route::post('/account/orders/pay', [TradeAccountController::class, 'payOrders'])->name('b2b.account.orders.pay');
        Route::post('/account/orders/callback', [TradeAccountController::class, 'paymentCallback'])->name('b2b.account.orders.callback');
        Route::post('/checkout/pay-on-account', [TradeAccountController::class, 'payOnAccount'])->name('b2b.checkout.pay-on-account');
    });
});
