<?php

use App\Http\Controllers\Api\V1\AuthController;
use App\Http\Controllers\Api\V1\Banner\BannerController;
use App\Http\Controllers\Api\V1\Brand\BrandController;
use App\Http\Controllers\Api\V1\Carousel\CarouselController;
use App\Http\Controllers\Api\V1\CartController;
use App\Http\Controllers\Api\V1\Category\CategoryController;
use App\Http\Controllers\Api\V1\Channel\ChannelController;
use App\Http\Controllers\Api\V1\Collection\CollectionController;
use App\Http\Controllers\Api\V1\ContactMessageController;
use App\Http\Controllers\Api\V1\Favorite\FavoriteController;
use App\Http\Controllers\Api\V1\Filters\FilterController;
use App\Http\Controllers\Api\V1\Legal\LegalPageController;
use App\Http\Controllers\Api\V1\NewsletterSubscriptionController;
use App\Http\Controllers\Api\V1\Order\OrderPaymentController;
use App\Http\Controllers\Api\V1\OrderController;
use App\Http\Controllers\Api\V1\PostBranch\PostBranchController;
use App\Http\Controllers\Api\V1\Product\Barcode\ProductBarcodeSearchController;
use App\Http\Controllers\Api\V1\Product\ProductController;
use App\Http\Controllers\Api\V1\Product\ProductRelatedController;
use App\Http\Controllers\Api\V1\Product\ProductReviewController;
use App\Http\Controllers\Api\V1\Product\Search\ProductSearchController;
use App\Http\Controllers\Api\V1\Product\ViewedProductController;
use App\Http\Controllers\Api\V1\Profile\ProfileController;
use App\Http\Controllers\Api\V1\Province\ProvinceController;
use App\Http\Controllers\Api\V1\ReviewController;
use App\Modules\GlobalOrder\Controllers\GlobalOrderController;
use Illuminate\Support\Facades\Route;

// Auth...
Route::post('auth/guest-token', [AuthController::class, 'guestToken']);
Route::post('auth/register', [AuthController::class, 'register']);
Route::post('auth/login', [AuthController::class, 'login']);
Route::post('auth/verify', [AuthController::class, 'verify']);
Route::middleware('auth:sanctum')
    ->post('auth/delete-user', [AuthController::class, 'delete']);

// Media...
Route::get('media/banners', [BannerController::class, 'index']);
Route::get('media/carousels', [CarouselController::class, 'index']);

// Forms...
Route::post('forms/newsletter-subscription', [NewsletterSubscriptionController::class, 'store']);
Route::middleware('auth:sanctum')
    ->post('forms/contact-us', [ContactMessageController::class, 'store']);

// Legal Pages...
Route::get('legal-pages', [LegalPageController::class, 'index']);
Route::get('legal-pages/{legalPage}', [LegalPageController::class, 'show']);

// Channels...
Route::get('channels', [ChannelController::class, 'index']);
Route::get('channels/{channel}', [ChannelController::class, 'show'])->where(['channel' => '[0-9]+']);
Route::get('channels/{channel}/products', [ChannelController::class, 'products'])->where(['channel' => '[0-9]+']);

// Brands...
Route::get('brands', [BrandController::class, 'index']);
Route::get('brands/{brand}', [BrandController::class, 'show'])->where(['brand' => '[0-9]+']);
Route::get('brands/{brand}/products', [BrandController::class, 'products'])->where(['brand' => '[0-9]+']);

// Categories...
Route::get('categories', [CategoryController::class, 'index']);
Route::get('categories/{category}', [CategoryController::class, 'show'])->where(['category' => '[0-9]+']);
Route::get('categories/{category}/products', [CategoryController::class, 'products'])->where(['category' => '[0-9]+']);

// Collections...
Route::get('collections', [CollectionController::class, 'index']);
Route::get('collections-paginated', [CollectionController::class, 'paginated']);
Route::get('collections/{collection}', [CollectionController::class, 'show'])->where(['collection' => '[0-9]+']);
Route::get('collections/{collection}/products', [CollectionController::class, 'products'])->where(['collection' => '[0-9]+']);

// Products...
Route::get('products', [ProductController::class, 'index']);
Route::get('products/{product}', [ProductController::class, 'show'])->where(['product' => '[0-9]+']);
Route::get('products/{product}/related', [ProductRelatedController::class, 'index'])->where(['product' => '[0-9]+']);

// Product barcode search
Route::get('search-product-barcode', [ProductBarcodeSearchController::class, 'index']);
Route::get('search-product', [ProductSearchController::class, 'index']);

// Product reviews...
Route::get('products/{product}/reviews', [ProductReviewController::class, 'index'])->where(['product' => '[0-9]+']);
Route::middleware('auth:sanctum')
    ->post('products/{product}/reviews', [ProductReviewController::class, 'store'])->where(['product' => '[0-9]+']);

// Order settings...
Route::get('order-time', [OrderController::class, 'time']);
Route::get('order-payments', [OrderPaymentController::class, 'index']);

// Provinces...
Route::get('provinces', [ProvinceController::class, 'index']);

// Post branches...
Route::get('post-branches', [PostBranchController::class, 'index']);

// Filters...
Route::get('filters', [FilterController::class, 'index']);

// Global orders...
Route::post('global-order', [GlobalOrderController::class, 'store']);

Route::middleware(['auth:sanctum', 'banned'])->group(function () {
    // Profile...
    Route::get('profile', [ProfileController::class, 'index']);
    Route::post('profile', [ProfileController::class, 'store']);

    // Cart items...
    Route::get('carts', [CartController::class, 'index']);
    Route::post('carts', [CartController::class, 'store']);
    Route::patch('carts', [CartController::class, 'remove']);
    Route::delete('carts', [CartController::class, 'destroy']);

    // Favorite products...
    Route::get('favorites', [FavoriteController::class, 'index']);
    Route::post('favorites', [FavoriteController::class, 'store']);

    // Viewed products...
    Route::get('products/viewed', [ViewedProductController::class, 'index']);

    // Reviews...
    Route::get('reviews', [ReviewController::class, 'index']);
    Route::patch('reviews/{review}', [ReviewController::class, 'update'])->where(['review' => '[0-9]+']);
    Route::delete('reviews/{review}', [ReviewController::class, 'destroy'])->where(['review' => '[0-9]+']);

    // Orders...
    Route::get('orders', [OrderController::class, 'index']);
    Route::get('orders/{order}', [OrderController::class, 'show'])->where(['order' => '[0-9]+']);
    Route::post('orders', [OrderController::class, 'store']);
    Route::delete('orders/{order}', [OrderController::class, 'destroy'])->where(['order' => '[0-9]+']);
});
