<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

// Auth routes (no auth required)
$routes->get('/', 'AuthController::login');
$routes->get('login', 'AuthController::login');
$routes->post('login', 'AuthController::login');
$routes->get('logout', 'AuthController::logout');
$routes->get('forgot-password', 'AuthController::forgotPassword');
$routes->post('forgot-password', 'AuthController::forgotPassword');

// Protected routes
$routes->group('', ['filter' => 'auth'], function($routes) {
    // Dashboard
    $routes->get('dashboard', 'DashboardController::index');

    // Invoices
    $routes->get('invoices', 'InvoiceController::index');
    $routes->get('invoices/create', 'InvoiceController::create');
    $routes->post('invoices/create', 'InvoiceController::store');
    $routes->get('invoices/view/(:num)', 'InvoiceController::view/$1');
    $routes->get('invoices/edit/(:num)', 'InvoiceController::edit/$1');
    $routes->post('invoices/edit/(:num)', 'InvoiceController::store');
    $routes->post('invoices/delete/(:num)', 'InvoiceController::delete/$1');
    $routes->get('invoices/pdf/(:num)', 'InvoiceController::pdf/$1');
    $routes->post('invoices/ajax-calculate', 'InvoiceController::ajaxCalculate');
    $routes->get('invoices/import', 'InvoiceController::importExcel');
    $routes->post('invoices/import', 'InvoiceController::importExcel');
    $routes->post('invoices/mark-paid/(:num)', 'InvoiceController::markPaid/$1');

    // Clients
    $routes->get('clients', 'ClientController::index');
    $routes->get('clients/create', 'ClientController::create');
    $routes->post('clients/create', 'ClientController::create');
    $routes->get('clients/view/(:num)', 'ClientController::view/$1');
    $routes->get('clients/edit/(:num)', 'ClientController::edit/$1');
    $routes->post('clients/edit/(:num)', 'ClientController::edit/$1');
    $routes->post('clients/delete/(:num)', 'ClientController::delete/$1');

    // Products
    $routes->get('products', 'ProductController::index');
    $routes->get('products/create', 'ProductController::create');
    $routes->post('products/create', 'ProductController::create');
    $routes->get('products/edit/(:num)', 'ProductController::edit/$1');
    $routes->post('products/edit/(:num)', 'ProductController::edit/$1');
    $routes->post('products/delete/(:num)', 'ProductController::delete/$1');
    $routes->get('products/ajax-list', 'ProductController::ajaxList');

    // Payments
    $routes->get('payments', 'PaymentController::index');
    $routes->get('payments/create/(:num)', 'PaymentController::create/$1');
    $routes->post('payments/create/(:num)', 'PaymentController::create/$1');

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

// API routes
$routes->group('api', ['filter' => 'auth'], function($routes) {
    $routes->get('invoices', 'InvoiceController::index');
    $routes->get('clients', 'ClientController::index');
    $routes->get('products/list', 'ProductController::ajaxList');
});

// CLI routes (migrations already handled by spark)
