<?php

use App\Http\Controllers\Admin\AdminPaymentController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\TransactionController;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\PayPalController;
use App\Http\Controllers\ShopController;
use App\Http\Controllers\SquareController;
use App\Http\Controllers\StripeController;
use Illuminate\Support\Facades\Route;

Route::post('/webhooks/stripe', [StripeController::class, 'webhook'])->name('webhooks.stripe');
Route::post('/webhooks/paypal', [PayPalController::class, 'webhook'])->name('webhooks.paypal');
Route::post('/webhooks/square', [SquareController::class, 'webhook'])->name('webhooks.square');

Route::get('/', [LandingController::class, 'index'])->name('welcome');
Route::get('/checkout', [CheckoutController::class, 'show'])->name('checkout');
Route::post('/checkout', [CheckoutController::class, 'submit'])->name('checkout.submit');

/** Public payment demo / checkout */
Route::get('/payments/checkout', [PaymentController::class, 'checkout'])->name('payments.checkout');
Route::post('/payments/session', [PaymentController::class, 'createSession'])
    ->middleware('throttle:30,1')
    ->name('payments.session');

Route::get('/payments/paypal/return', [PayPalController::class, 'return'])->name('payments.paypal.return');
Route::get('/payments/paypal/cancel', [PayPalController::class, 'cancel'])->name('payments.paypal.cancel');

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

/** Public shop */
Route::get('/shop', [ShopController::class, 'index'])->name('shop.index');
Route::get('/shop/{product:slug}', [ShopController::class, 'show'])->name('shop.show');

Route::get('/pages/ingredients', [PageController::class, 'ingredients'])->name('pages.ingredients');
Route::get('/pages/bee-cause', [PageController::class, 'beeCause'])->name('pages.bee_cause');
Route::get('/pages/our-story', [PageController::class, 'ourStory'])->name('pages.our_story');

/** Admin */
Route::middleware(['auth', 'admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    Route::resource('categories', CategoryController::class)->except(['show']);
    Route::resource('products', ProductController::class)->except(['show']);

    Route::get('payments', [AdminPaymentController::class, 'index'])->name('payments.index');
    Route::get('payments/gateways/{gateway}/edit', [AdminPaymentController::class, 'edit'])->name('payments.edit');
    Route::put('payments/gateways/{gateway}', [AdminPaymentController::class, 'update'])->name('payments.update');

    Route::get('transactions', [TransactionController::class, 'index'])->name('transactions.index');
    Route::get('transactions/export', [TransactionController::class, 'export'])->name('transactions.export');
    Route::get('transactions/analytics', [TransactionController::class, 'analytics'])->name('transactions.analytics');
    Route::get('transactions/{transaction}', [TransactionController::class, 'show'])->name('transactions.show');
    Route::post('transactions/{transaction}/refund', [TransactionController::class, 'refund'])->name('transactions.refund');
});
