<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CouponController;
use App\Http\Controllers\BrandController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\AdminController;
use App\Http\Middleware\AdminMiddleware;
use App\Http\Controllers\HomePage;
use App\Http\Controllers\CartController;
use App\Http\Controllers\StripeController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\CheckoutController;






Route::get('/', function () {
    return view('index');
});

Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
});




Route::middleware(['auth',AdminMiddleware::class])->
group(function(){

Route::get('/admin/dashboard',[AdminController::class,
'index'])->
name('admin.dashboard');




Route::resource('brands',BrandController::class);
Route::resource('dashboard',DashboardController::class);
    Route::resource('products',ProductController::class);
    Route::resource('categories',CategoryController::class);
    Route::resource('orders',OrderController::class);
    Route::resource('coupons',CouponController::class);
    Route::resource('payments',PaymentController::class);


});














//Routes for user interface
Route::get('/product',[HomePage::class,'index'])->name('products.index');
Route::get('/product/{product}',[HomePage::class,'show'])->
name('product.show');
Route::post('/cart/add/{product}',[CartController::class,'add'])
->name('cart.add');
Route::get('/cart',[CartController::class,'index'])
->name('cart.index');
Route::post('/cart/update',[CartController::class,'update'])
->name('cart.update');
Route::post('/cart/remove/{id}',[CartController::class,'remove'])
->name('cart.remove');


Route::get('/checkout',[StripeController::class,'checkout'])->name('checkout');
Route::get('/session',[StripeController::class,'createCheckoutSession'])->name('checkout.session');

Route::get('/success',[StripeController::class,'success'])->name('checkout.success');

Route::get('/cancel',[StripeController::class,'cancel'])->name('checkout.cancel');

Route::get('/invoice/{order}',[OrderController::class,'invoice'])->name('order.invoice');


Route::get('/cart/checkout',[CheckoutController::class,'show'])->name('checkout.show');
Route::post('/checkout/cash',[CheckoutController::class,'placeCashOrder'])->name('checkout.cash');

Route::post('/checkout/stripe/intent',[CheckoutController::class,'createStripeIntent'])->name('checkout.stripe.intent');
