<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */

$routes->get('/', 'AuthController::showLogin');

// ---- لوحة الأدمن ----
$routes->group('admin', function ($routes) {
    $routes->get('login', 'AuthController::showLogin');
    $routes->post('login', 'AuthController::login');
    $routes->post('logout', 'AuthController::logout');
    $routes->get('switch-company/(:num)', 'AuthController::switchCompany/$1', ['filter' => 'adminAuth']);

    $routes->get('verify-code', 'AuthController::showVerify');
    $routes->post('verify-code', 'AuthController::verify');
    $routes->post('resend-code', 'AuthController::resendCode');

    $routes->group('', ['filter' => 'adminAuth'], function ($routes) {
        $routes->get('dashboard', 'Admin\DashboardController::index');

        $routes->get('clients', 'Admin\ClientController::index');
        $routes->get('clients/create', 'Admin\ClientController::create');
        $routes->post('clients', 'Admin\ClientController::store');
        $routes->get('clients/(:num)/edit', 'Admin\ClientController::edit/$1');
        $routes->post('clients/(:num)', 'Admin\ClientController::update/$1');
        $routes->post('clients/(:num)/delete', 'Admin\ClientController::delete/$1');

        $routes->get('services', 'Admin\ServiceController::index');
        $routes->get('services/create', 'Admin\ServiceController::create');
        $routes->post('services', 'Admin\ServiceController::store');
        $routes->get('services/(:num)/edit', 'Admin\ServiceController::edit/$1');
        $routes->post('services/(:num)', 'Admin\ServiceController::update/$1');
        $routes->post('services/(:num)/delete', 'Admin\ServiceController::delete/$1');

        $routes->get('invoices', 'Admin\InvoiceController::index');
        $routes->get('invoices/create', 'Admin\InvoiceController::create');
        $routes->post('invoices', 'Admin\InvoiceController::store');
        $routes->get('invoices/(:num)/edit', 'Admin\InvoiceController::edit/$1');
        $routes->post('invoices/(:num)', 'Admin\InvoiceController::update/$1');
        $routes->post('invoices/(:num)/delete', 'Admin\InvoiceController::delete/$1');
        $routes->post('invoices/(:num)/payments', 'Admin\InvoiceController::addPayment/$1');
        $routes->get('invoices/(:num)/view', 'Admin\InvoiceController::view/$1');
        $routes->get('invoices/(:num)/pdf', 'Admin\InvoiceController::downloadPdf/$1');

        $routes->get('quotes', 'Admin\QuoteController::index');
        $routes->get('quotes/create', 'Admin\QuoteController::create');
        $routes->post('quotes', 'Admin\QuoteController::store');
        $routes->get('quotes/(:num)/edit', 'Admin\QuoteController::edit/$1');
        $routes->post('quotes/(:num)', 'Admin\QuoteController::update/$1');
        $routes->post('quotes/(:num)/delete', 'Admin\QuoteController::delete/$1');
        $routes->get('quotes/(:num)/view', 'Admin\QuoteController::view/$1');
        $routes->get('quotes/(:num)/pdf', 'Admin\QuoteController::downloadPdf/$1');
        $routes->post('quotes/(:num)/convert', 'Admin\QuoteController::convertToInvoice/$1');

        $routes->get('reports/profit', 'Admin\ReportController::profit');
        $routes->get('logs', 'Admin\ActivityLogController::index');

        $routes->get('site-settings', 'Admin\SiteSettingsController::edit');
        $routes->post('site-settings', 'Admin\SiteSettingsController::update');

        $routes->get('site-slides', 'Admin\SiteSlideController::index');
        $routes->get('site-slides/create', 'Admin\SiteSlideController::create');
        $routes->post('site-slides', 'Admin\SiteSlideController::store');
        $routes->get('site-slides/(:num)/edit', 'Admin\SiteSlideController::edit/$1');
        $routes->post('site-slides/(:num)', 'Admin\SiteSlideController::update/$1');
        $routes->post('site-slides/(:num)/delete', 'Admin\SiteSlideController::delete/$1');

        $routes->get('site-testimonials', 'Admin\TestimonialController::index');
        $routes->get('site-testimonials/create', 'Admin\TestimonialController::create');
        $routes->post('site-testimonials', 'Admin\TestimonialController::store');
        $routes->get('site-testimonials/(:num)/edit', 'Admin\TestimonialController::edit/$1');
        $routes->post('site-testimonials/(:num)', 'Admin\TestimonialController::update/$1');
        $routes->post('site-testimonials/(:num)/delete', 'Admin\TestimonialController::delete/$1');

        $routes->get('contact-messages', 'Admin\ContactMessageController::index');
        $routes->post('contact-messages/(:num)/read', 'Admin\ContactMessageController::markRead/$1');
        $routes->post('contact-messages/(:num)/delete', 'Admin\ContactMessageController::delete/$1');

        $routes->get('expenses', 'Admin\ExpenseController::index');
        $routes->get('expenses/create', 'Admin\ExpenseController::create');
        $routes->post('expenses', 'Admin\ExpenseController::store');
        $routes->get('expenses/(:num)/edit', 'Admin\ExpenseController::edit/$1');
        $routes->post('expenses/(:num)', 'Admin\ExpenseController::update/$1');
        $routes->post('expenses/(:num)/delete', 'Admin\ExpenseController::delete/$1');

        $routes->get('products', 'Admin\ProductController::index');
        $routes->get('products/create', 'Admin\ProductController::create');
        $routes->post('products', 'Admin\ProductController::store');
        $routes->get('products/(:num)/edit', 'Admin\ProductController::edit/$1');
        $routes->post('products/(:num)', 'Admin\ProductController::update/$1');
        $routes->post('products/(:num)/delete', 'Admin\ProductController::delete/$1');

        $routes->get('marketers', 'Admin\MarketerController::index');
        $routes->get('marketers/create', 'Admin\MarketerController::create');
        $routes->post('marketers', 'Admin\MarketerController::store');
        $routes->get('marketers/(:num)/edit', 'Admin\MarketerController::edit/$1');
        $routes->post('marketers/(:num)', 'Admin\MarketerController::update/$1');
        $routes->post('marketers/(:num)/delete', 'Admin\MarketerController::delete/$1');

        $routes->get('exchange-rates', 'Admin\ExchangeRateController::index');
        $routes->get('exchange-rates/create', 'Admin\ExchangeRateController::create');
        $routes->post('exchange-rates', 'Admin\ExchangeRateController::store');
        $routes->get('exchange-rates/(:num)/edit', 'Admin\ExchangeRateController::edit/$1');
        $routes->post('exchange-rates/(:num)', 'Admin\ExchangeRateController::update/$1');
        $routes->post('exchange-rates/(:num)/delete', 'Admin\ExchangeRateController::delete/$1');

        $routes->get('companies', 'Admin\CompanyController::index');
        $routes->get('companies/create', 'Admin\CompanyController::create');
        $routes->post('companies', 'Admin\CompanyController::store');
        $routes->get('companies/(:num)/edit', 'Admin\CompanyController::edit/$1');
        $routes->post('companies/(:num)', 'Admin\CompanyController::update/$1');

        $routes->get('users', 'Admin\UserController::index');
        $routes->get('users/create', 'Admin\UserController::create');
        $routes->post('users', 'Admin\UserController::store');
        $routes->get('users/(:num)/edit', 'Admin\UserController::edit/$1');
        $routes->post('users/(:num)', 'Admin\UserController::update/$1');
        $routes->post('users/(:num)/delete', 'Admin\UserController::delete/$1');
        $routes->post('users/(:num)/renew', 'Admin\UserController::renew/$1');

        $routes->get('settings', 'Admin\SettingsController::edit');
        $routes->post('settings', 'Admin\SettingsController::update');

        $routes->get('currencies', 'Admin\CurrencyController::index');
        $routes->get('currencies/create', 'Admin\CurrencyController::create');
        $routes->post('currencies', 'Admin\CurrencyController::store');
        $routes->get('currencies/(:num)/edit', 'Admin\CurrencyController::edit/$1');
        $routes->post('currencies/(:num)', 'Admin\CurrencyController::update/$1');
        $routes->post('currencies/(:num)/delete', 'Admin\CurrencyController::delete/$1');
    });
});

// ---- بوابة العميل ----
// ---- الموقع الإلكتروني العام (لكل الشركات، بدون تسجيل دخول) ----
$routes->group('site', function ($routes) {
    $routes->get('(:segment)', 'Site\SiteController::home/$1');
    $routes->get('(:segment)/about', 'Site\SiteController::about/$1');
    $routes->get('(:segment)/products', 'Site\SiteController::products/$1');
    $routes->get('(:segment)/contact', 'Site\SiteController::contact/$1');
    $routes->post('(:segment)/contact', 'Site\SiteController::submitContact/$1');
});

$routes->group('client', function ($routes) {
    $routes->get('login', 'Client\AuthController::showLogin');
    $routes->post('login', 'Client\AuthController::login');
    $routes->post('logout', 'Client\AuthController::logout');

    $routes->group('', ['filter' => 'clientAuth'], function ($routes) {
        $routes->get('dashboard', 'Client\DashboardController::index');
        $routes->get('invoices', 'Client\InvoiceController::index');
        $routes->get('invoices/(:num)', 'Client\InvoiceController::show/$1');
        $routes->get('services', 'Client\ServiceController::index');
    });
});
