<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\Provider\Digiflazz\FetchProductController;

// User
use App\Http\Controllers\User\DashboardController as UserDashboard;
use App\Http\Controllers\User\TopupController as UserTopup;
use App\Http\Controllers\User\ProductController as UserProduct;
use App\Http\Controllers\User\HistoryTransactionController as UserHistoryTransaction;
use App\Http\Controllers\User\BalanceLogController as UserBalanceLog;
use App\Http\Controllers\User\ApiSettingController as UserApiSetting;
use App\Http\Controllers\User\IpWhitelistController as UserIpWhitelist;
use App\Http\Controllers\User\ApiDocumentationController;

// Admin
use App\Http\Controllers\Admin\DashboardController as AdminDashboard;
use App\Http\Controllers\Admin\AnalyticsController;
use App\Http\Controllers\Admin\SettingController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\TransactionController;
use App\Http\Controllers\Admin\PaymentMethodController;
use App\Http\Controllers\Admin\TopupController;

// Guest
Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/produk', [UserProduct::class, 'index'])->name('product.index');
Route::get('/api-docs', [ApiDocumentationController::class, 'index'])->name('api-docs.index');
Route::get('/hubungi-kami', [ContactController::class, 'index'])->name('contact.index');

// Route User
Route::middleware('auth')->group(function () {
    Route::get('/dashboard', [UserDashboard::class, 'index'])->name('dashboard');

    Route::get('/topup', [UserTopup::class, 'index'])->name('user.topup.index');
    Route::get('/topup/create', [UserTopup::class, 'create'])->name('user.topup.create');
    Route::post('/topup', [UserTopup::class, 'store'])->name('user.topup.store');
    Route::get('/topup/{topup:topup_id}/show', [UserTopup::class, 'show'])->name('user.topup.show');

    Route::get('/history-transaksi', [UserHistoryTransaction::class, 'index'])->name('user.history.index');
    Route::get('/mutasi-saldo', [UserBalanceLog::class, 'index'])->name('user.balance-log.index');

    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::get('/api-credentials', [UserApiSetting::class, 'index'])->name('user.api-credentials.index');
    Route::post('/api-credentials/renew', [UserApiSetting::class, 'renew'])->name('user.api-credentials.renew');
    
    Route::get('/ip-whitelist', [UserIpWhitelist::class, 'index'])->name('user.ip-whitelist.index');
    Route::post('/ip-whitelist', [UserIpWhitelist::class, 'store'])->name('user.ip-whitelist.store');
    Route::delete('/ip-whitelist', [UserIpWhitelist::class, 'destroy'])->name('user.ip-whitelist.destroy');
    Route::delete('/ip-whitelist/clear', [UserIpWhitelist::class, 'clear'])->name('user.ip-whitelist.clear');

});

// Route Admin
Route::middleware(['auth', 'admin'])->prefix('admin')->group(function () {
    Route::get('/dashboard', [AdminDashboard::class, 'index'])->name('admin.dashboard');
    Route::get('/analytics', [AnalyticsController::class, 'index'])->name('admin.analytics');
    Route::get('/settings', [SettingController::class, 'index'])->name('admin.settings');
    Route::post('/settings', [SettingController::class, 'update'])->name('admin.settings.update');

    Route::get('/users', [UserController::class, 'index'])->name('admin.users.index');
    Route::get('/users/{user}/edit', [UserController::class, 'edit'])->name('admin.users.edit');
    Route::put('/users/{user}', [UserController::class, 'update'])->name('admin.users.update');
    Route::delete('/users/{user}', [UserController::class, 'destroy'])->name('admin.users.destroy');

    Route::get('/products', [ProductController::class, 'index'])->name('admin.products.index');
    Route::get('/products/create', [ProductController::class, 'create'])->name('admin.products.create');
    Route::post('/products', [ProductController::class, 'store'])->name('admin.products.store');
    Route::get('/products/{product}/edit', [ProductController::class, 'edit'])->name('admin.products.edit');
    Route::put('/products/{product}', [ProductController::class, 'update'])->name('admin.products.update');
    Route::delete('/products/{product}', [ProductController::class, 'destroy'])->name('admin.products.destroy');

    Route::get('/transactions', [TransactionController::class, 'index'])->name('admin.transactions.index');
    Route::get('/transactions/{transaction}/edit', [TransactionController::class, 'edit'])->name('admin.transactions.edit');
    Route::put('/transactions/{transaction}', [TransactionController::class, 'update'])->name('admin.transactions.update');
    Route::delete('/transactions/{transaction}', [TransactionController::class, 'destroy'])->name('admin.transactions.destroy');

    Route::get('/payment-methods', [PaymentMethodController::class, 'index'])->name('admin.payment-methods.index');
    Route::get('/payment-methods/create', [PaymentMethodController::class, 'create'])->name('admin.payment-methods.create');
    Route::post('/payment-methods', [PaymentMethodController::class, 'store'])->name('admin.payment-methods.store');
    Route::get('/payment-methods/{paymentMethod}/edit', [PaymentMethodController::class, 'edit'])->name('admin.payment-methods.edit');
    Route::put('/payment-methods/{paymentMethod}', [PaymentMethodController::class, 'update'])->name('admin.payment-methods.update');
    Route::delete('/payment-methods/{paymentMethod}', [PaymentMethodController::class, 'destroy'])->name('admin.payment-methods.destroy');

    Route::get('/topups', [TopupController::class, 'index'])->name('admin.topups.index');
    Route::get('/topups/{topup}/show', [TopupController::class, 'show'])->name('admin.topups.show');
    Route::post('/topups/{topup}/reject', [TopupController::class, 'reject'])->name('admin.topups.reject');
    Route::post('/topups/{topup}/approve', [TopupController::class, 'approve'])->name('admin.topups.approve');
    Route::delete('/topups/{topup}', [TopupController::class, 'destroy'])->name('admin.topups.destroy');
    
    Route::get('/fetch-digiflazz-products', [FetchProductController::class, 'fetchProduct'])->name('admin.fetch.digiflazz.products');
});

require __DIR__.'/auth.php';
