<?php

use App\Http\Controllers\API\AuthController;
use App\Http\Controllers\API\BranchController;
use App\Http\Controllers\API\BrandController;
use App\Http\Controllers\API\CartController;
use App\Http\Controllers\API\CategoryController;
use App\Http\Controllers\API\CompanyController;
use App\Http\Controllers\API\OrderController;
use App\Http\Controllers\API\CompilationController;
use App\Http\Controllers\API\FavoriteController;
use App\Http\Controllers\API\FeedbackController;
use App\Http\Controllers\API\FirebaseController;
use App\Http\Controllers\API\PageController;
use App\Http\Controllers\API\PartnerController;
use App\Http\Controllers\API\PaymentSystemController;
use App\Http\Controllers\API\ProductController;
use App\Http\Controllers\API\ServiceController;
use App\Http\Controllers\API\SliderController;
use App\Http\Controllers\API\UsefulInfoController;
use App\Http\Controllers\API\RequestsController;
use App\Http\Controllers\API\SupportController;
use App\Http\Controllers\API\UserController;
use Illuminate\Support\Facades\Route;
// //
Route::prefix('oauth')->group(function () {
    Route::post('/', [AuthController::class, 'auth']);
    Route::post('/verify', [AuthController::class, 'verify']);
    Route::post('/register', [AuthController::class, 'register']);
    Route::post('/resend', [AuthController::class, 'resend']);
});

Route::middleware('auth:sanctum')->group(function () {
    Route::post('/oauth/logout', [AuthController::class, 'logout']);

    Route::delete('/user/me', [UserController::class, 'delete']);
    Route::get('/user/me', [UserController::class, 'me']);
    Route::put('/user/language', [UserController::class, 'changeLang']);
    Route::put('/user/me', [UserController::class, 'update']);
    Route::get('/user/orders', [OrderController::class, 'list']);
    Route::get('/user/orders/{order_id}', [OrderController::class, 'show']);
    Route::get('/favorites', [FavoriteController::class, 'index']);

    Route::get('/user/requests', [RequestsController::class, 'getServiceRequests']);
    Route::get('/user/requests/partner', [RequestsController::class, 'getPartnerRequests']);
    Route::get('/user/requests/{service_request_id}', [RequestsController::class, 'show']);

    // Route::post('/checkout/delivery-price', [OrderController::class, 'delivery_price']);
    // Route::post('/checkout/installation-price', [OrderController::class, 'installation_price']);
    Route::post('/checkout', [OrderController::class, 'checkout']);
    Route::post('/checkout-preview', [OrderController::class, 'preview']);
    Route::post('/order/{order_id}/payment-check-status', [OrderController::class, 'checkPaymentStatus']);

    //    Route::get('/favorites', [FavoriteController::class, 'index']);
    Route::get('/products/{product_id}/favorites', [FavoriteController::class, 'store']);
    Route::delete('/products/{product_id}/favorites', [FavoriteController::class, 'destroy']);

    Route::post('/partners', [PartnerController::class, 'store']);
});

Route::get('/payment-systems/{type}', [PaymentSystemController::class, 'legal']);

Route::get('/branches', [BranchController::class, 'index']);
Route::get('/regions', [PageController::class, 'regions']);
Route::get('/powers', [PageController::class, 'powers']);
Route::get('/feedback', [FeedbackController::class, 'get']);
Route::get('/company', [CompanyController::class, 'get']);
Route::post("/support", [SupportController::class, 'store']);

Route::prefix('page')->group(function () {
    Route::get('/about', [PageController::class, 'about']);
    Route::get('/policy', [PageController::class, 'policy']);
});

Route::get('/brands', [BrandController::class, 'index']);

Route::prefix('sliders')->group(function () {
    Route::get('/', [SliderController::class, 'index']);
    Route::get('/{slider_id}', [SliderController::class, 'show']);
});

Route::get('/compilations/{id}', [CompilationController::class, 'show']);
Route::get('/compilations', [CompilationController::class, 'index']);

Route::prefix('useful-information')->group(function () {
    Route::get('/', [UsefulInfoController::class, 'index']);
    Route::get('/{id}', [UsefulInfoController::class, 'items']);
    Route::get('/{id}/items/{item_id}', [UsefulInfoController::class, 'itemShow']);
});

Route::prefix('partners')->group(function () {
    Route::get('/', [PartnerController::class, 'index']);
    Route::get('/{partner_id}', [PartnerController::class, 'show']);
});

Route::get('problems', [ServiceController::class, 'getProblems']);

Route::prefix('services')->group(function () {
    Route::get('/', [ServiceController::class, 'index']);
    Route::get('/{esrvice_id}', [ServiceController::class, 'show']);
    Route::post('/', [ServiceController::class, 'store'])->middleware('auth:sanctum');
});

Route::prefix('categories')->group(function () {
    Route::get('/', [CategoryController::class, 'index']);
    Route::get('/{category_id}/products', [CategoryController::class, 'products']);
    Route::get('/{category_id}/filter', [CategoryController::class, 'filter']);
});

Route::get('/{brand_id}/products', [ProductController::class, 'productsByBrand']);
Route::get('/products/{product_id}', [ProductController::class, 'show']);

Route::get('/search', [ProductController::class, 'search']);
Route::post('/device', [FirebaseController::class, 'store']);

Route::prefix('cart')->group(function () {
    Route::get('/', [CartController::class, 'getCart']);
    Route::post('/', [CartController::class, 'addToCart']);
    Route::delete('/{cart_id}', [CartController::class, 'delete']);

    Route::put('/{cart}/add', [CartController::class, 'add']);
    Route::put('/{cart}/decrease', [CartController::class, 'decrease']);
});

Route::any('/handle/{paysys}', function ($paysys) {
    (new Goodoneuz\PayUz\PayUz)->driver($paysys)->handle();
});
