<?php

use Illuminate\Support\Facades\Route;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Category\Controllers\Canteen\CategoryController;
use Modules\Order\Controllers\Canteen\OrderController;
use Modules\PaymentLog\Controllers\Canteen\PaymentLogController;
use Modules\Product\Controllers\Canteen\ProductController;
use Modules\Product\Controllers\Canteen\ProductStockController;
use Modules\School\Controllers\Admin\SchoolController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use App\Http\Middleware\CheckWebSiteEnabled;
use Modules\User\Controllers\Canteen\DashboardController;
use Modules\User\Controllers\Canteen\LoginController;
use Modules\User\Controllers\Canteen\ProfileController;
use Modules\User\Controllers\Canteen\UserController;

/**
 * Localization Group
 */

Route::group(['prefix' => LaravelLocalization::setLocale()], function(){



    /**
     * Web Routes
     */
    Route::group([ 'prefix'=> 'canteen' ], function () {
        Route::get('/login', [LoginController::class,'index'])->name('canteen_login');
        Route::post('/login',  [LoginController::class,'authenticate'])->name('canteen_authenticate');
        Route::group([ 'middleware' => ['canteen_auth']], function () {
            Route::get('/', [DashboardController::class,'index'])->name('dashboard');
            Route::post('/logout', [LoginController::class,'logout'])->name('canteen_logout');
            Route::get('/logout', [LoginController::class,'logout'])->name('canteen_logout');
        });
        Route::get('fetch/products',[ProductStockController::class,'fetchProducts'])->name('canteen.product.fetch');

        Route::group([ 'middleware' => ['canteen_auth']], function () {


            Route::group([ 'middleware' => ['checkCanteenRole']], function () {

                // User ROUTES
                Route::put('/users/restore/{id}', [UserController::class,'restore'])->name('canteen.users.restore');
                Route::put('/users/restore', [UserController::class,'restoreAll'])->name('canteen.users.restoreAll');
                Route::delete('/users', [UserController::class,'destroyAll'])->name('canteen.users.destroyAll');
                Route::get('/users/grid', [UserController::class,'grid'])->name('canteen.users.grid');
                Route::resource('/users', UserController::class)->names('canteen.users');

                Route::get('/profile', [ProfileController::class,'profile'])->name('canteen.profile.index');
                Route::post('/profile', [ProfileController::class,'editProfile'])->name('canteen.profile.edit');

                Route::get('/statistics', [UserController::class,'statistics'])->name('canteen.statistics.index');

                // PaymentLog ROUTES
                Route::put('/payment_logs/restore/{id}', [PaymentLogController::class,'restore'])->name('canteen.payment_logs.restore');
                Route::put('/payment_logs/restore', [PaymentLogController::class,'restoreAll'])->name('canteen.payment_logs.restoreAll');
                Route::delete('/payment_logs', [PaymentLogController::class,'destroyAll'])->name('canteen.payment_logs.destroyAll');
                Route::get('/payment_logs/grid', [PaymentLogController::class,'grid'])->name('canteen.payment_logs.grid');
                Route::resource('/payment_logs', PaymentLogController::class)->names('canteen.payment_logs');

                // Product ROUTES
                Route::put('/products/restore/{id}', [ProductController::class,'restore'])->name('canteen.products.restore');
                Route::put('/products/restore', [ProductController::class,'restoreAll'])->name('canteen.products.restoreAll');
                Route::delete('/products', [ProductController::class,'destroyAll'])->name('canteen.products.destroyAll');
                Route::get('/products/grid', [ProductController::class,'grid'])->name('canteen.products.grid');
                Route::resource('/products', ProductController::class)->names('canteen.products');

                // Category ROUTES
                Route::put('/categories/restore/{id}', [CategoryController::class,'restore'])->name('canteen.categories.restore');
                Route::put('/categories/restore', [CategoryController::class,'restoreAll'])->name('canteen.categories.restoreAll');
                Route::delete('/categories', [CategoryController::class,'destroyAll'])->name('canteen.categories.destroyAll');
                Route::get('/categories/grid', [CategoryController::class,'grid'])->name('canteen.categories.grid');
                Route::resource('/categories', CategoryController::class)->names('canteen.categories');

                // Order ROUTES
                Route::get('/orders/grid', [OrderController::class,'grid'])->name('canteen.orders.grid');
                Route::resource('/orders', OrderController::class)->names('canteen.orders')->except(['destroy','show']);


                // Stock ROUTES
                Route::get('/stocks/report', [ProductStockController::class,'report'])->name('canteen.stocks.report');
                Route::post('/stocks/report', [ProductStockController::class,'reporting'])->name('canteen.stocks.reporting');
                Route::get('/stocks/grid', [ProductStockController::class,'grid'])->name('canteen.stocks.grid');
                Route::resource('/stocks', ProductStockController::class)->names('canteen.stocks')->except(['edit','update','destroy']);

            });  // End Role Routes

            // Route::post('/languages/{id}', 'LanguageController@update')->name('languages');

        }); // End Authenticated Web routes
    }); // End Web Routes

});
