<?php

use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\FoodDistributionController;
use App\Http\Controllers\OmsClientController;
use App\Http\Controllers\OmsDealerController;
use App\Http\Controllers\PermissionController;

// Public Routes
Route::get('/', function () {
    return view('welcome');
});

// Protected Routes (লগইন করা ইউজার এবং যাদের পারমিশন আছে তারাই এক্সেস পাবে)
Route::middleware(['auth', 'verified', 'check.route'])->group(function () {

    // Dashboard Route (Updated)
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    // Profile Routes
    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');

    // Settings Routes
    Route::get('/settings', [SettingController::class, 'index'])->name('settings.index');
    Route::post('/settings', [SettingController::class, 'update'])->name('settings.update');

    // Admin Routes (Users)
    Route::prefix('admin')->name('admin.')->group(function () {
        Route::get('/users/create', [UserController::class, 'create'])->name('users.create');
        Route::post('/users/store', [UserController::class, 'store'])->name('users.store');
        Route::get('/users', [UserController::class, 'index'])->name('users.index');

        Route::get('/users/{id}/edit', [UserController::class, 'edit'])->name('users.edit');
        Route::put('/users/{id}', [UserController::class, 'update'])->name('users.update');

        // ইউজার ডিলিট করার রাউট
        Route::delete('/users/{id}', [UserController::class, 'destroy'])->name('users.destroy');
    });


    // Permission Management Routes 
    Route::get('/users/{user}/permissions', [PermissionController::class, 'edit'])->name('permissions.edit');
    Route::post('/users/{user}/permissions', [PermissionController::class, 'update'])->name('permissions.update');



    Route::prefix('oms-dealers')->name('oms_dealers.')->group(function () {
        Route::get('/', [OmsDealerController::class, 'index'])->name('index');
        Route::get('/create', [OmsDealerController::class, 'create'])->name('create');
        Route::post('/store', [OmsDealerController::class, 'store'])->name('store');
        Route::get('/{id}/edit', [OmsDealerController::class, 'edit'])->name('edit');
        Route::put('/{id}/update', [OmsDealerController::class, 'update'])->name('update');
        Route::delete('/{id}/delete', [OmsDealerController::class, 'destroy'])->name('destroy');
        Route::get('/{id}/print', [OmsDealerController::class, 'print'])->name('print');
    });



    Route::prefix('oms-clients')->name('oms_clients.')->group(function () {
        Route::get('/', [OmsClientController::class, 'index'])->name('index');
        Route::get('/create', [OmsClientController::class, 'create'])->name('create');
        Route::post('/store', [OmsClientController::class, 'store'])->name('store');
        Route::get('/{id}/edit', [OmsClientController::class, 'edit'])->name('edit');
        Route::put('/{id}/update', [OmsClientController::class, 'update'])->name('update');
        Route::delete('/{id}/delete', [OmsClientController::class, 'destroy'])->name('destroy');
        Route::get('/{id}/print', [OmsClientController::class, 'print'])->name('print');

        // AJAX Route
        Route::get('/dealer-details/{id}', [OmsClientController::class, 'getDealerDetails'])->name('dealer_details');
    });



    Route::prefix('distributions')->name('distributions.')->group(function () {
        Route::get('/', [FoodDistributionController::class, 'index'])->name('index');
        Route::get('/select-word', [FoodDistributionController::class, 'selectWord'])->name('select_word');
        Route::post('/process-word', [FoodDistributionController::class, 'processWord'])->name('process_word');
        Route::get('/distribute/{dealer_id}', [FoodDistributionController::class, 'distribute'])->name('distribute');
        Route::post('/scan-verify', [FoodDistributionController::class, 'scanVerify'])->name('scan_verify');
    });



    Route::get('/distributions', [FoodDistributionController::class, 'index'])->name('distributions.index');
    Route::get('/distributions/print', [FoodDistributionController::class, 'print'])->name('distributions.print');


});



require __DIR__ . '/auth.php';