<?php

use Illuminate\Support\Facades\Route;
use Modules\Address\Controllers\Api\AddressController;
use Modules\Category\Controllers\Api\CategoryController;
use Modules\Chip\Controllers\Api\ChipController;
use Modules\ChipOrder\Controllers\Api\ChipOrderController;
use Modules\City\Controllers\Api\CityController;
use Modules\Notification\Controllers\Api\NotificationController;
use Modules\Order\Controllers\Api\OrderController;
use Modules\Package\Controllers\Api\PackageController;
use Modules\PaymentLog\Controllers\Api\PaymentLogController;
use Modules\Product\Controllers\Api\ProductController;
use Modules\Setting\Controllers\Api\SettingController;
use Modules\Subscription\Controllers\Api\SubscriptionController;
use Modules\User\Controllers\Api\AuthController;
use Modules\User\Controllers\Api\ChildrenController;
use Modules\School\Controllers\Api\SchoolController;
use Modules\User\Controllers\Api\UserController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group([
    //'namespace' => 'Api',
    'middleware' => ['check.api.secret', 'WebsiteVisitorCount', 'set.current.lang', 'idempotency']
], function () {
    //Auth

    Route::post('/login', [AuthController::class, 'login']);
    Route::post('/send-code', [AuthController::class, 'sendCode']);
    Route::post('/verify-code', [AuthController::class, 'checkCode']);
    Route::post('/register', [AuthController::class, 'store']);
    Route::post('/change-password', [AuthController::class, 'resetPassword']);
    Route::get('/info', [SettingController::class, 'index']);
    Route::get('/faqs', [SettingController::class, 'faqs']);
    Route::get('/pages', [SettingController::class, 'pages']);
    Route::group(['prefix' => 'cities'], function () {
        Route::get('/', [CityController::class, 'index']);
        Route::get('/{city}', [CityController::class, 'show']);
    });
    Route::group(['middleware' => ['api_auth']], function () {
        Route::group(['prefix' => 'chips'], function () {
            Route::get('/', [ChipController::class, 'index']);
            Route::get('/{chip}', [ChipController::class, 'show']);

        });
        Route::group(['prefix' => 'chip-orders'], function () {
            Route::get('/', [ChipOrderController::class, 'index']);
            Route::get('/{chipOrder}', [ChipOrderController::class, 'show']);
            Route::post('/', [ChipOrderController::class, 'store']);
            Route::post('/create', [ChipOrderController::class, 'createOrder']);
        });
        Route::get('/schools', [SchoolController::class, 'index']);
        Route::group(['prefix' => 'products'], function () {
            Route::get('/{canteen?}', [ProductController::class, 'index']);
            Route::get('/show/{product}', [ProductController::class, 'show']);
            Route::post('/', [ProductController::class, 'store']);
            Route::post('/edit/{product}', [ProductController::class, 'update']);
            Route::delete('/{product}', [ProductController::class, 'delete']);
        });
        Route::group(['prefix' => 'orders'], function () {
            Route::get('/{children?}', [OrderController::class, 'index']);
            Route::get('/{children}/products', [OrderController::class, 'products']);
            Route::post('/', [OrderController::class, 'store']);
        });

        Route::group(['prefix' => 'packages'], function () {
            Route::get('/', [PackageController::class, 'index']);
        });
        Route::group(['prefix' => 'notifications'], function () {
            Route::get('/', [NotificationController::class, 'index']);
        });
        Route::group(['prefix' => 'subscriptions'], function () {
            Route::get('/', [SubscriptionController::class, 'index']);
            Route::post('/create', [SubscriptionController::class, 'createSubscription']);
            Route::post('/', [SubscriptionController::class, 'store']);
        });
        Route::group(['prefix' => 'categories'], function () {
            Route::get('/{canteen?}', action: [CategoryController::class, 'index']);
            Route::get('/show/{category}', [CategoryController::class, 'show']);
            Route::post('/', [CategoryController::class, 'store']);
            Route::put('/{category}', [CategoryController::class, 'update']);
            Route::delete('/{category}', [CategoryController::class, 'delete']);
        });
        Route::group(['prefix' => 'users'], function () {

            Route::get('/', [UserController::class, 'show']);
            Route::post('/edit', [UserController::class, 'update']);
            Route::patch('/', [UserController::class, 'logout']);
            Route::delete('/', [UserController::class, 'delete']);
            Route::group(['prefix' => 'childrens'], function () {
                Route::get('/', action: [ChildrenController::class, 'index']);
                Route::get('/{children}', [ChildrenController::class, 'show']);
                Route::post('/', [ChildrenController::class, 'store']);
                Route::post('/edit', [ChildrenController::class, 'update']);
                Route::delete('/{children}', [ChildrenController::class, 'delete']);
                Route::post('/products/{children}', [ChildrenController::class, 'blockedProducts']);
            });
            Route::group(['prefix' => 'addresses'], function () {
                Route::get('/', action: [AddressController::class, 'index']);
                Route::get('/{address}', [AddressController::class, 'show']);
                Route::post('/', [AddressController::class, 'store']);
                Route::put('/{address}', [AddressController::class, 'update']);
                Route::delete('/{address}', [AddressController::class, 'delete']);
            });
            Route::get('/payment/logs', [PaymentLogController::class, 'index']);
            Route::post('/payment/logs/create', [PaymentLogController::class, 'create']);
        });
    });
});
