<?php

use Illuminate\Support\Facades\Route;
use Modules\Banner\Controllers\Api\BannerController;
use Modules\Brand\Controllers\Api\BrandController;
use Modules\Category\Controllers\Api\CategoryController;
use Modules\City\Controllers\Api\CityController;
use Modules\Country\Controllers\Api\CountryController;
use Modules\FaqCategory\Controllers\Api\FaqCategoryController;
use Modules\Offer\Controllers\Api\OfferController;
use Modules\Order\Controllers\Api\CartController;
use Modules\Order\Controllers\Api\OrderController;
use Modules\Page\Controllers\Api\PageController;
use Modules\PaymentWay\Controllers\Api\PaymentWayController;
use Modules\Product\Controllers\Api\ProductController;
use Modules\Rate\Controllers\Api\RateController;
use Modules\Reason\Controllers\Api\ReasonController;
use Modules\Refund\Controllers\Api\RefundController;
use Modules\Region\Controllers\Api\RegionController;
use Modules\Setting\Controllers\Api\SettingController;
use Modules\Type\Controllers\Api\TypeController;
use Modules\User\Controllers\Api\AddressController;
use Modules\User\Controllers\Api\AuthController;
use Modules\User\Controllers\Api\PaymentCardController;

/*
|--------------------------------------------------------------------------
| 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(['middleware' => ['TokenCheck','AuthApi'],'prefix' => 'v1', 'namespace' => 'API'],function(){

    //Info
    Route::get('settings',[SettingController::class,'settings']);
    Route::get('intro',[PageController::class,'intro']);

    Route::post('sendCode',[AuthController::class,'sendCode']);
    Route::post('login',[AuthController::class,'login']);

    Route::group(['prefix' => 'countries'],function(){
        Route::get('/',[CountryController::class,'index']);
        Route::get('/{id}',[CountryController::class,'show']);
    });

    Route::group(['prefix' => 'regions'],function(){
        Route::get('/',[RegionController::class,'index']);
        Route::get('/{id}',[RegionController::class,'show']);
    });

    Route::group(['prefix' => 'cities'],function(){
        Route::get('/',[CityController::class,'index']);
        Route::get('/{id}',[CityController::class,'show']);
    });

    Route::group(['prefix' => 'brands'],function(){
        Route::get('/',[BrandController::class,'index']);
        Route::get('/{id}',[BrandController::class,'show']);
    });

    Route::group(['prefix' => 'faqs'],function(){
        Route::get('/',[FaqCategoryController::class,'index']);
        Route::get('/{id}',[FaqCategoryController::class,'show']);
    });

    Route::group(['prefix' => 'types'],function(){
        Route::get('/',[TypeController::class,'index']);
        Route::get('/{id}',[TypeController::class,'show']);
    });

    Route::group(['prefix' => 'categories'],function(){
        Route::get('/',[CategoryController::class,'index']);
        Route::get('/{id}',[CategoryController::class,'show']);
    });

    Route::group(['prefix' => 'reasons'],function(){
        Route::get('/',[ReasonController::class,'index']);
        Route::get('/{id}',[ReasonController::class,'show']);
    });

    Route::group(['prefix' => 'offers'],function(){
        Route::get('/',[OfferController::class,'index']);
        Route::get('/{id}',[OfferController::class,'show']);
    });

    Route::group(['prefix' => 'carts'],function(){
        Route::get('/',[CartController::class,'index']);
        Route::get('/{id}',[CartController::class,'show']);
        Route::post('create',[CartController::class,'create']);
        Route::put('edit/{id}',[CartController::class,'edit']);
        Route::delete('delete/{id}',[CartController::class,'delete']);
        Route::post('calculate',[CartController::class,'calculate']);
    });

    Route::post('filter',[ProductController::class,'index']);
    Route::post('visit',[CategoryController::class,'visit']);
    Route::group(['prefix' => 'products'],function(){
        Route::get('/recommended',[ProductController::class,'recommended']);
        Route::get('/most/sold',[ProductController::class,'mostSold']);
        Route::get('/{id}',[ProductController::class,'show']);
    });

    Route::group(['prefix' => 'payment/ways'],function(){
        Route::get('/',[PaymentWayController::class,'index']);
        Route::get('/{id}',[PaymentWayController::class,'show']);
    });

    Route::group(['prefix' => 'banners'],function(){
        Route::get('/home',[BannerController::class,'home']);
        Route::get('/footer',[BannerController::class,'footer']);
        Route::get('/category/{id}',[BannerController::class,'category']);
        Route::get('/{id}',[BannerController::class,'show']);
    });

    Route::put('/changeType',[AuthController::class,'changeType']);
    Route::put('/changeCity',[AuthController::class,'changeCity']);

    Route::group(['prefix' => 'profile'],function(){
        Route::get('/',[AuthController::class,'profile']);
        Route::put('/',[AuthController::class,'editProfile'])->middleware('StrictAuthApi');
    });

    Route::group(['prefix' => 'profile'],function(){
        Route::get('/',[AuthController::class,'profile']);
        Route::put('/',[AuthController::class,'editProfile'])->middleware('StrictAuthApi');
    });

    Route::group(['prefix' => 'favorite'],function(){
        Route::get('/',[ProductController::class,'favorites']);
        Route::post('/',[ProductController::class,'favorite']);
    });

    Route::group(['prefix' => 'rates'],function(){
        Route::get('/{id}',[RateController::class,'rates']);
        Route::post('/',[RateController::class,'rate'])->middleware('StrictAuthApi');
    });

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

        Route::group(['prefix' => 'addresses'],function(){
            Route::get('/',[AddressController::class,'index']);
            Route::get('/{id}',[AddressController::class,'show']);
            Route::post('create',[AddressController::class,'create']);
            Route::put('edit/{id}',[AddressController::class,'edit']);
            Route::delete('delete/{id}',[AddressController::class,'delete']);
        });

        Route::group(['prefix' => 'payment/cards'],function(){
            Route::get('/',[PaymentCardController::class,'index']);
            Route::get('/{id}',[PaymentCardController::class,'show']);
            Route::post('create',[PaymentCardController::class,'create']);
            Route::put('edit/{id}',[PaymentCardController::class,'edit']);
            Route::delete('delete/{id}',[PaymentCardController::class,'delete']);
        });

        Route::group(['prefix' => 'orders'],function(){
            Route::get('/',[OrderController::class,'index']);
            Route::get('/{id}',[OrderController::class,'show']);
            Route::post('/create',[OrderController::class,'create']);
        });

        Route::group(['prefix' => 'refunds'],function(){
            Route::get('/',[RefundController::class,'index']);
            Route::get('/{id}',[RefundController::class,'show']);
            Route::post('/create',[RefundController::class,'create']);
        });

        Route::delete('/logout',[AuthController::class,'logout']);
        Route::delete('/deactivate',[AuthController::class,'deactivate']);



    });

});
