<?php

use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\ClientController;
use App\Http\Controllers\PaymentController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\ServiceController;

Route::get('/', function () {
    return view('welcome');
})->name('home');

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('/dashboard', [ServiceController::class, 'index'])->name('dashboard');
    Route::get('/riwayat-pembelanjaan', [ServiceController::class, 'history'])->name('orders.history');
    Route::get('/services/{service}', [ServiceController::class, 'show'])->name('services.show');

    Route::post('/payment/paypal', [PaymentController::class, 'createPayment'])->name('payment.create');
    Route::get('/payment/paypal/success', [PaymentController::class, 'capturePayment'])->name('payment.success');
    Route::get('/payment/paypal/cancel', [PaymentController::class, 'cancelPayment'])->name('payment.cancel');
    Route::post('/payment/qris/{service}', [PaymentController::class, 'startQris'])->name('payment.qris.start');
    Route::get('/payment/qris/{service}/{order}', [PaymentController::class, 'showQris'])->name('payment.qris.show');

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

Route::middleware(['auth', 'verified', 'admin'])
    ->prefix('admin')
    ->name('admin.')
    ->group(function () {
        Route::get('/produk', [ProductController::class, 'index'])->name('products.index');
        Route::post('/produk', [ProductController::class, 'store'])->name('products.store');
        Route::get('/produk/{service}/edit', [ProductController::class, 'edit'])->name('products.edit');
        Route::patch('/produk/{service}', [ProductController::class, 'update'])->name('products.update');

        Route::get('/clients', [ClientController::class, 'create'])->name('clients.create');
        Route::post('/clients', [ClientController::class, 'store'])->name('clients.store');
        Route::get('/clients/{client}/edit', [ClientController::class, 'edit'])->name('clients.edit');
        Route::patch('/clients/{client}', [ClientController::class, 'update'])->name('clients.update');
    });

require __DIR__.'/auth.php';
