<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */
$routes->get('/', 'Home::index');

// REST API Routes Group
$routes->group('api', function ($routes) {
    // Authentication & Users
    $routes->post('auth/register', 'AuthController::register');
    $routes->post('auth/login', 'AuthController::login');
    $routes->get('auth/profile', 'AuthController::profile');
    $routes->post('auth/profile/update', 'AuthController::updateProfile');
    $routes->get('users', 'AuthController::index');
    $routes->post('users/(:num)/update', 'AuthController::updateUser/$1');
    $routes->post('users/(:num)/verify', 'AuthController::verifyUser/$1');
    $routes->post('auth/forgot-password', 'AuthController::forgotPassword');
    $routes->post('auth/reset-password', 'AuthController::resetPassword');

    // System Settings
    $routes->get('settings', 'SettingsController::index');
    $routes->post('settings', 'SettingsController::update');

    // Marketplace Products
    $routes->get('products', 'ProductController::index');
    $routes->get('products/(:num)', 'ProductController::show/$1');
    $routes->get('products/(:num)/reviews', 'ReviewController::getProductReviews/$1');
    $routes->post('products', 'ProductController::create');
    $routes->get('products/recommendations', 'ProductController::recommendations');
    $routes->get('products/image/(:any)', 'ProductController::serveImage/$1');
    $routes->post('products/(:num)/update', 'ProductController::updateProduct/$1');
    $routes->post('products/(:num)/delete', 'ProductController::deleteProduct/$1');
    
    // Uploads
    $routes->post('upload/image', 'ProductController::uploadImage');

    // Orders
    $routes->get('orders', 'OrderController::index');
    $routes->get('orders/(:num)', 'OrderController::show/$1');
    $routes->post('orders', 'OrderController::create');
    $routes->post('reviews', 'ReviewController::submitReview');
    $routes->post('orders/(:num)/status', 'OrderController::updateStatus/$1');

    // Cooperative Portal & Supervision
    $routes->get('cooperatives', 'CooperativeController::index');
    $routes->get('cooperatives/stats', 'CooperativeController::stats');
    $routes->post('cooperatives', 'CooperativeController::create');
    $routes->post('cooperatives/(:num)/status', 'CooperativeController::updateStatus/$1');
    $routes->post('cooperatives/(:num)/update', 'CooperativeController::updateProfile/$1');
    $routes->post('cooperatives/(:num)/delete', 'CooperativeController::delete/$1');
    $routes->get('audit-logs', 'CooperativeController::auditLogs');
    $routes->post('audit-logs/clear', 'CooperativeController::clearAuditLogs');

    // Regions CRUD
    $routes->get('regions', 'RegionController::index');
    $routes->post('regions', 'RegionController::create');
    $routes->post('regions/(:num)/update', 'RegionController::update/$1');
    $routes->post('regions/(:num)/delete', 'RegionController::delete/$1');

    // BI Reports
    $routes->get('reports/bi', 'ReportController::getBiReport');

    // Product Messages & Seller Inbox
    $routes->get('messages', 'MessageController::index');
    $routes->get('messages/thread', 'MessageController::thread');
    $routes->get('messages/customer', 'MessageController::customerThreads');
    $routes->post('messages', 'MessageController::send');
    $routes->get('messages/unread-count', 'MessageController::unreadCount');
    $routes->get('messages/customer-unread-count', 'MessageController::customerUnreadCount');

    // AI Helper Features
    $routes->post('ai/chatbot', 'AiController::chatbot');
    $routes->post('ai/seller-assistant', 'AiController::sellerAssistant');
    $routes->post('ai/review-analysis', 'AiController::reviewAnalysis');
});
