<?php
declare(strict_types=1);

use Helpers\Router;
use Helpers\Request;
use Middleware\CorsMiddleware;
use Middleware\SecurityHeadersMiddleware;
use Controllers\ProductController;
use Controllers\CategoryController;
use Controllers\BlogController;
use Controllers\OrderController;
use Controllers\PaymentController;
use Controllers\LeadController;
use Controllers\SeoController;
use Controllers\SystemController;

use Controllers\AuthController;
use Controllers\CartController;
use Controllers\AddressController;
use Controllers\CheckoutController;
use Controllers\UserOrderController;
use Controllers\AdminOrderController;
use Controllers\AdminCatalogController;
use Controllers\AdminUserController;

CorsMiddleware::handle();
SecurityHeadersMiddleware::handle();

$router = new Router();

$router->get('/api/health', [SystemController::class, 'health']);

$router->post('/api/auth/register', [AuthController::class, 'register']);
$router->post('/api/auth/login', [AuthController::class, 'login']);
$router->post('/api/auth/logout', [AuthController::class, 'logout']);
$router->get('/api/auth/me', [AuthController::class, 'me']);

$router->get('/api/cart', [CartController::class, 'index']);
$router->post('/api/cart/add', [CartController::class, 'add']);
$router->put('/api/cart/update', [CartController::class, 'update']);
$router->delete('/api/cart/remove', [CartController::class, 'remove']);

$router->get('/api/addresses', [AddressController::class, 'index']);
$router->post('/api/addresses', [AddressController::class, 'create']);
$router->put('/api/addresses/{id}', [AddressController::class, 'update']);
$router->delete('/api/addresses/{id}', [AddressController::class, 'delete']);
$router->patch('/api/addresses/{id}/default', [AddressController::class, 'setDefault']);

$router->post('/api/checkout/validate', [CheckoutController::class, 'validate']);
$router->get('/api/pincode/{pin}', [CheckoutController::class, 'pincode']);
$router->get('/api/orders/{orderNumber}/invoice', [UserOrderController::class, 'invoice']);
$router->get('/api/orders/{orderNumber}', [UserOrderController::class, 'show']);
$router->get('/api/orders', [UserOrderController::class, 'index']);
$router->get('/api/admin/dashboard', [AdminCatalogController::class, 'dashboard']);
$router->get('/api/admin/leads', [AdminCatalogController::class, 'leads']);
$router->get('/api/admin/delivery-zones', [AdminCatalogController::class, 'deliveryZones']);
$router->post('/api/admin/delivery-zones', [AdminCatalogController::class, 'saveDeliveryZone']);
$router->get('/api/admin/categories', [AdminCatalogController::class, 'categories']);
$router->post('/api/admin/categories', [AdminCatalogController::class, 'createCategory']);
$router->put('/api/admin/categories/{id}', [AdminCatalogController::class, 'updateCategory']);
$router->delete('/api/admin/categories/{id}', [AdminCatalogController::class, 'deleteCategory']);

$router->get('/api/admin/orders', [AdminOrderController::class, 'index']);
$router->get('/api/admin/orders/{id}', [AdminOrderController::class, 'show']);
$router->patch('/api/admin/orders/{id}/status', [AdminOrderController::class, 'updateStatus']);
$router->patch('/api/admin/orders/{id}/tracking', [AdminOrderController::class, 'updateTracking']);

$router->get('/api/admin/products', [AdminCatalogController::class, 'products']);
$router->get('/api/admin/products/{id}', [AdminCatalogController::class, 'product']);
$router->post('/api/admin/products', [AdminCatalogController::class, 'createProduct']);
$router->put('/api/admin/products/{id}', [AdminCatalogController::class, 'updateProduct']);
$router->delete('/api/admin/products/{id}', [AdminCatalogController::class, 'deleteProduct']);

$router->get('/api/admin/blogs', [AdminCatalogController::class, 'blogs']);
$router->get('/api/admin/blogs/{id}', [AdminCatalogController::class, 'blog']);
$router->post('/api/admin/blogs', [AdminCatalogController::class, 'createBlog']);
$router->post('/api/admin/upload', [AdminCatalogController::class, 'uploadImage']);
$router->put('/api/admin/blogs/{id}', [AdminCatalogController::class, 'updateBlog']);
$router->delete('/api/admin/blogs/{id}', [AdminCatalogController::class, 'deleteBlog']);


$router->get('/api/products', [ProductController::class, 'index']);
$router->get('/api/products/{slug}', [ProductController::class, 'show']);
$router->get('/api/categories', [CategoryController::class, 'index']);
$router->get('/api/categories/{slug}/products', [CategoryController::class, 'products']);
$router->get('/api/blogs', [BlogController::class, 'index']);
$router->get('/api/blogs/{slug}', [BlogController::class, 'show']);
$router->post('/api/orders/cod', [OrderController::class, 'cod']);
$router->post('/api/payments/razorpay/create-order', [PaymentController::class, 'createRazorpayOrder']);
$router->post('/api/payments/razorpay/verify', [PaymentController::class, 'verify']);
$router->post('/api/payments/razorpay/failed', [PaymentController::class, 'failed']);
$router->post('/api/bulk-orders', [LeadController::class, 'bulkOrder']);
$router->post('/api/distributor-inquiries', [LeadController::class, 'distributor']);
$router->post('/api/contact', [LeadController::class, 'contact']);
$router->get('/api/seo/sitemap-data', [SeoController::class, 'sitemapData']);

$router->get('/api/admin/users', [AdminUserController::class, 'index']);
$router->get('/api/admin/users/{id}', [AdminUserController::class, 'show']);
$router->patch('/api/admin/users/{id}/role', [AdminUserController::class, 'updateRole']);
$router->patch('/api/admin/users/{id}/status', [AdminUserController::class, 'updateStatus']);

$router->dispatch(Request::method(), Request::path());
